Packages
errors
A small family of error types with a code and details, returned by
charset and encaps. Most errors you will handle are
not these: each package exports its own sentinel errors and types, tested with
the standard errors.Is and errors.As.
import "github.com/amrshadid/go-dicom/errors" · pkg.go.dev
When to use it
- Tell a character set failure from charset (
*DicomUnicodeDecodeError) or an encapsulation failure from encaps (*EncapsulationError) apart from other errors, and read its code.
For everything else, test the error the package that returned it documents. The common ones:
| Package | Errors |
|---|---|
| filereader | ErrValueTooLong, ErrHeaderTooLarge, ErrTruncated, *ReadError and ErrorKind |
| dataset | ErrUndecodedSyntax, ErrNoEncoder, ErrLossyNotAllowed, ErrPixelSizeOverflow, *ICCProfileError |
| compress | ErrFrameMismatch, ErrJPEGXLNotDecoded |
| network | *StatusError, *AssociationError, *TimeoutError, IsCanceled |
| dicomweb | *StatusError, ErrResponseTooLarge, ErrPartTooLarge |
| volume | *Error with a Kind |
| fileset | ErrNotDICOM, ErrNoFileMeta, ErrInvalidFileID, ErrTooManyRecords |
Key types and functions
| Name | What it is for |
|---|---|
DicomError | The interface every type here satisfies: Error, ErrorCode, Details. |
DicomUnicodeDecodeError | A character set that is unknown, or text that cannot be decoded or encoded. |
EncapsulationError | Encapsulated pixel data that cannot be parsed or split. |
InvalidDicomError, InvalidVRError, InvalidValueError | Other types with constructors, for code of your own. |
DicomKeyError, DicomInvalidTagError, DicomBytesLengthError | The same. |
Example
// Tell an encoding failure apart from other errors, and read its code.
package main
import (
"context"
stderrors "errors"
"fmt"
"github.com/amrshadid/go-dicom/charset"
"github.com/amrshadid/go-dicom/config"
dicomerrors "github.com/amrshadid/go-dicom/errors"
)
func main() {
ctx := config.StrictReading(context.Background())
_, err := charset.ConvertEncodingsWithContext(ctx, []string{"ISO_IR 999"})
var decodeErr *dicomerrors.DicomUnicodeDecodeError
if stderrors.As(err, &decodeErr) {
fmt.Println("encoding:", decodeErr.Encoding)
fmt.Println("code:", decodeErr.ErrorCode())
}
// Every type here satisfies DicomError.
var de dicomerrors.DicomError
if stderrors.As(err, &de) {
fmt.Println("details:", de.Details())
}
}It prints encoding: ISO_IR 999, code: UNICODE_DECODE_ERROR and the
details. The package is imported under another name so that the standard
errors stays available.
Notes
- The package name is
errors, which shadows the standard library's. Import it asdicomerrorsor similar. - The
Execute…Hookfunctions return maps describing an error; nothing in the library calls them.
Note
Of the types here, only DicomUnicodeDecodeError and EncapsulationError
are returned by the library itself. The others exist for callers who want the
same shape for their own errors.