Skip to content

Constants & Errors ​

This page collects the exported constants of CyberGo html (default configuration, format values, audit events and levels), the 12 sentinel errors, and the three structured error types, together with the errors.Is/errors.As decision patterns.

Default Configuration Constants ​

ConstantTypeValueDescription
DefaultMaxInputSizeint52428800Maximum input size (50 MB)
DefaultMaxCacheEntriesint2000Cache entry limit
DefaultWorkerPoolSizeint4Concurrent worker goroutines for batch extraction
DefaultCacheTTLtime.Duration1hCache entry lifetime
DefaultCacheCleanuptime.Duration5mBackground sweep interval for expired cache entries
DefaultMaxAuditEntriesint10000In-memory audit entry limit (used when AuditConfig.MaxEntries is 0)
DefaultMaxRawValueLengthint200Maximum length of the audit RawValue string
DefaultMaxDepthint500Maximum HTML nesting depth (stack-overflow guard)
DefaultProcessingTimeouttime.Duration30sProcessing timeout

Audit Constants ​

Audit Event Types ​

ConstantValueDescription
AuditEventBlockedTag"blocked_tag"Blocked tag
AuditEventBlockedAttr"blocked_attr"Blocked attribute
AuditEventBlockedURL"blocked_url"Blocked URL
AuditEventInputViolation"input_violation"Input violation
AuditEventDepthViolation"depth_violation"Depth violation
AuditEventTimeout"timeout"Processing timeout
AuditEventEncodingIssue"encoding_issue"Encoding issue
AuditEventPathTraversal"path_traversal"Path traversal attempt

Audit Levels ​

ConstantTypeValueDescription
AuditLevelInfoAuditLevel"info"Information level
AuditLevelWarningAuditLevel"warning"Warning level
AuditLevelCriticalAuditLevel"critical"Critical level

For audit usage and Sink types see Audit System.

Format Constants ​

Value constants for the InlineImageFormat, InlineLinkFormat, and TableFormat fields; assign them instead of magic strings (e.g. cfg.InlineImageFormat = html.FormatMarkdown):

ConstantValueApplicable fieldsDescription
FormatNone"none"InlineImageFormat / InlineLinkFormatNot inlined into Text; not valid for TableFormat
FormatMarkdown"markdown"InlineImageFormat / InlineLinkFormat / TableFormatInlines with Markdown syntax; the MarkdownConfig() preset assigns this constant internally
FormatHTML"html"InlineImageFormat / InlineLinkFormat / TableFormatKeeps inline HTML tags
FormatPlaceholder"placeholder"InlineImageFormat onlyEmits an [IMAGE:N] positional placeholder

InlineImageFormat / InlineLinkFormat default to FormatNone and TableFormat defaults to FormatMarkdown; validation is case-insensitive, ignores leading and trailing whitespace, and treats an empty string as the field default — the full option lists per field are in Config. Reader mode (ReadPage*) always preserves links and treats InlineLinkFormat's FormatNone as FormatMarkdown; see Reader Mode.

Sentinel Errors ​

ErrorMessageDescription
ErrInputTooLargehtml: input size exceeds maximumInput exceeds the size limit
ErrInvalidHTMLhtml: invalid HTMLInvalid HTML content
ErrProcessorClosedhtml: processor closedProcessor is closed
ErrMaxDepthExceededhtml: max depth exceededMaximum depth exceeded
ErrInvalidConfightml: invalid configInvalid configuration
ErrProcessingTimeouthtml: processing timeout exceededThe library's processing timeout elapsed
ErrFileNotFoundhtml: file not foundFile not found
ErrInvalidFilePathhtml: invalid file pathInvalid file path
ErrInternalPanichtml: internal panic recoveredInternal panic recovered (a library defect; report it to the maintainers)
ErrMultipleConfigshtml: at most one Config may be providedMore than one Config passed
ErrBatchTooLargehtml: batch size exceeds maximumBatch item count exceeds the per-batch limit (10000)
ErrTooManyConcurrentOpshtml: too many concurrent operationsTimeout watchdog reached its process-wide limit (1000); no timeout occurred

When the user's context deadline expires, the call returns context.DeadlineExceeded, which is not normalized to ErrProcessingTimeout.

Error Types ​

InputError ​

InputError is the error type for input problems, carrying size information.

go
type InputError struct {
	Op       string // Operation name
	Size     int    // Actual size
	MaxSize  int    // Maximum limit
	InputErr error  // Original error
}

func (e *InputError) Error() string
func (e *InputError) Unwrap() []error // [InputErr, ErrInputTooLarge] if InputErr is non-nil, otherwise [ErrInputTooLarge]
MemberTypeDescription
InputError.OpstringName of the failed operation (e.g. "Extract", "ExtractFromFile")
InputError.SizeintActual input size
InputError.MaxSizeintConfigured size limit
InputError.InputErrerrorUnderlying error (may be nil)
MethodDescription
InputError.ErrorFormats the message, including actual and limit sizes
InputError.Unwrap[InputErr, ErrInputTooLarge] when InputErr is non-nil, otherwise [ErrInputTooLarge]

Unwrap returns a slice of errors, not a single error. ErrInputTooLarge is always in the list, whether or not an underlying error is carried, so errors.Is(err, ErrInputTooLarge) holds for any *InputError.

ConfigError ​

ConfigError is the error type for configuration validation, carrying field information.

go
type ConfigError struct {
	Field   string // Field name
	Value   any    // Invalid value
	Message string // Error description
}

func (e *ConfigError) Error() string
func (e *ConfigError) Unwrap() error // → ErrInvalidConfig
MemberTypeDescription
ConfigError.FieldstringName of the invalid config field (e.g. "MaxInputSize")
ConfigError.ValueanyThe rejected field value
ConfigError.MessagestringError description (e.g. "must be positive")
MethodDescription
ConfigError.ErrorFormats as html: invalid config: field=value, description
ConfigError.UnwrapReturns ErrInvalidConfig

FileError ​

FileError is the error type for file operations; it truncates paths on output.

go
type FileError struct {
	Op      string // Operation name
	Path    string // File path
	FileErr error  // Original error
}

func (e *FileError) Error() string                // Safe output (truncated path)
func (e *FileError) SafePath() string             // Filename only
func (e *FileError) Unwrap() error                // → ErrFileNotFound | original error (including path traversal denials wrapping ErrInvalidFilePath) | ErrInvalidFilePath
func (e *FileError) MarshalJSON() ([]byte, error) // Truncates Path via SafePath() when serialized
MemberTypeDescription
FileError.OpstringName of the failed operation (e.g. "ExtractFromFile", "ReadFile")
FileError.PathstringFull file path (debugging only; do not output directly)
FileError.FileErrerrorUnderlying filesystem error
MethodDescription
FileError.ErrorSafe output (path truncated to the filename; the underlying message is redacted too)
FileError.SafePathReturns the filename only (returned as-is when there is no separator)
FileError.Unwrap→ ErrFileNotFound | the original error | ErrInvalidFilePath (path traversal denials wrap ErrInvalidFilePath, so errors.Is matches)
FileError.MarshalJSONSerializes as {op, path, message} with path truncated via SafePath()

A safe default when emitting paths

FileError.Error() and SafePath() both return only the filename, so they are safe to put in HTTP responses or logs. Read the Path field for the full path, and only for internal debugging.

Which file error matches no sentinel

Path traversal (a .. component that survives cleaning) returns a *FileError wrapping ErrInvalidFilePath, so errors.Is(err, ErrInvalidFilePath) is true. The single exception is an AllowedBaseDir sandbox escape: FileErr is path outside allowed directory, which matches no sentinel error, so inspect the message in FileError.FileErr.

Internal Limit Constants ​

The constants below define runtime hard limits. They are unexported (lowercase) and cannot be referenced directly, but they determine boundary behavior.

Configuration Upper Bounds ​

ConstantValueDescription
maxConfigInputSize52428800 (50 MB)Upper bound for MaxInputSize; larger values are rejected by Validate()
maxConfigWorkerSize256Upper bound for WorkerPoolSize
maxConfigDepth500Upper bound for MaxDepth
maxConfigCacheEntries100000Upper bound for MaxCacheEntries (about 100 MB at 1 KB per entry)
maxConfigAuditEntries100000Upper bound for Audit.MaxEntries; the in-memory limit of GetAuditLog

Processing Limits ​

ConstantValueDescription
maxBatchSize10000Maximum items per batch; exceeding it fails the whole batch
maxTimeoutGoroutines1000Process-wide limit on concurrent timeout goroutines; new requests beyond it return ErrTooManyConcurrentOps
maxHTMLForRegex1000000 (1 MB)Size limit for the raw-HTML media scan; above it the whole scan is skipped (ReDoS prevention)
maxRegexMatches1000Maximum media-URL matches per scan; prevents excessive allocation on media-dense pages

How these limits play out:

  • For HTML over 1 MB, the raw-HTML scan (<iframe>/<embed>/<object> tag attributes and bare media URLs) does not run; the DOM walk still extracts <video>/<audio>.
  • A batch over 10000 items fails as a whole (returning ErrBatchTooLarge, not a panic); it does not process the first 10000 only.
  • When more than 1000 timed calls are running concurrently within the process, new calls return ErrTooManyConcurrentOps immediately; retry after in-flight operations drain.

Error Handling Patterns ​

go
result, err := html.Extract(data)
if err != nil {
	var inputErr *html.InputError
	var configErr *html.ConfigError
	var fileErr *html.FileError

	switch {
	case errors.Is(err, html.ErrInvalidConfig):
		// Config error: errors.As yields the offending field and reason
		if errors.As(err, &configErr) {
			fmt.Printf("Config field %s invalid: %s\n", configErr.Field, configErr.Message)
		}
	case errors.Is(err, html.ErrInputTooLarge):
		// Input too large: errors.As yields the actual size and limit
		if errors.As(err, &inputErr) {
			fmt.Printf("Size %d exceeds limit %d\n", inputErr.Size, inputErr.MaxSize)
		}
	case errors.Is(err, html.ErrInvalidHTML):
		// Invalid HTML
	case errors.Is(err, html.ErrFileNotFound):
		// File not found
	case errors.Is(err, html.ErrInvalidFilePath):
		// Invalid path; path traversal denials match this sentinel too
	case errors.As(err, &fileErr):
		// Other file errors (e.g. an AllowedBaseDir escape, which matches no sentinel)
		fmt.Println("File:", fileErr.SafePath())
	}
}