validation

package
v3.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

README

OCFL Validation

The validation package provides structures and functions for handling OCFL validation errors and warnings. It maps OCFL specification error codes to descriptive error objects.

Key Components

ErrorCode

A string type representing an OCFL validation error or warning code (e.g., E001, W001).

Error

A struct that contains detailed information about a validation issue:

  • Code: The ErrorCode.
  • Description: The official description from the OCFL specification.
  • Ref: A URL to the relevant section in the OCFL specification.
  • Description2: Additional dynamic information about the specific occurrence of the error.
  • Context: The architectural context where the error occurred (e.g., "storage root", "object root").
  • Version: The OCFL version the error refers to.
Status

A structure that collects all validation errors and warnings encountered during a validation run. Use NewStatus() to create one.

Usage

Collecting Errors

Validation errors are typically managed via the OCFLLogger in the pkg/ocfllogger package, which uses this package to create and store errors.

To manually create a validation error:

vErr := validation.GetValidationError(version.OCFLVersion("1.1"), validation.E001)
vErr = vErr.AppendContext("object root").AppendDescription("found unexpected file: %s", filename)

To add it to a status collector:

status := validation.NewStatus()
status.Add(vErr)
Retrieving and Processing Results

After the validation process is complete, you can process the collected errors:

// Remove duplicates and sort by context/code
status.Compact()

for _, vErr := range status.Errors {
    fmt.Println(vErr.Error())
}

Error Definitions

The package includes comprehensive mappings for OCFL validation codes for different versions. These mappings include the official description and a reference link to the specification.

OCFL Version 1.0
OCFL Version 1.1

Documentation

Overview

Package validation provides structures and functions for handling OCFL validation errors and warnings.

It maps OCFL specification error codes to descriptive error objects and provides a mechanism to collect these errors during the validation process. Base error definitions are loaded from validationerror1_0.go and validationerror1_1.go.

Index

Constants

View Source
const (
	E000 = ErrorCode("E000") // Unknown error
	E001 = ErrorCode("E001")
	E002 = ErrorCode("E002")
	E003 = ErrorCode("E003")
	E004 = ErrorCode("E004")
	E005 = ErrorCode("E005")
	E006 = ErrorCode("E006")
	E007 = ErrorCode("E007")
	E008 = ErrorCode("E008")
	E009 = ErrorCode("E009")
	E010 = ErrorCode("E010")
	E011 = ErrorCode("E011")
	E012 = ErrorCode("E012")
	E013 = ErrorCode("E013")
	E014 = ErrorCode("E014")
	E015 = ErrorCode("E015")
	E016 = ErrorCode("E016")
	E017 = ErrorCode("E017")
	E018 = ErrorCode("E018")
	E019 = ErrorCode("E019")
	E020 = ErrorCode("E020")
	E021 = ErrorCode("E021")
	E022 = ErrorCode("E022")
	E023 = ErrorCode("E023")
	E024 = ErrorCode("E024")
	E025 = ErrorCode("E025")
	E026 = ErrorCode("E026")
	E027 = ErrorCode("E027")
	E028 = ErrorCode("E028")
	E029 = ErrorCode("E029")
	E030 = ErrorCode("E030")
	E031 = ErrorCode("E031")
	E032 = ErrorCode("E032")
	E033 = ErrorCode("E033")
	E034 = ErrorCode("E034")
	E035 = ErrorCode("E035")
	E036 = ErrorCode("E036")
	E037 = ErrorCode("E037")
	E038 = ErrorCode("E038")
	E039 = ErrorCode("E039")
	E040 = ErrorCode("E040")
	E041 = ErrorCode("E041")
	E042 = ErrorCode("E042")
	E043 = ErrorCode("E043")
	E044 = ErrorCode("E044")
	E045 = ErrorCode("E045")
	E046 = ErrorCode("E046")
	E047 = ErrorCode("E047")
	E048 = ErrorCode("E048")
	E049 = ErrorCode("E049")
	E050 = ErrorCode("E050")
	E051 = ErrorCode("E051")
	E052 = ErrorCode("E052")
	E053 = ErrorCode("E053")
	E054 = ErrorCode("E054")
	E055 = ErrorCode("E055")
	E056 = ErrorCode("E056")
	E057 = ErrorCode("E057")
	E058 = ErrorCode("E058")
	E059 = ErrorCode("E059")
	E060 = ErrorCode("E060")
	E061 = ErrorCode("E061")
	E062 = ErrorCode("E062")
	E063 = ErrorCode("E063")
	E064 = ErrorCode("E064")
	E066 = ErrorCode("E066")
	E067 = ErrorCode("E067")
	E068 = ErrorCode("E068")
	E069 = ErrorCode("E069")
	E070 = ErrorCode("E070")
	E071 = ErrorCode("E071")
	E072 = ErrorCode("E072")
	E073 = ErrorCode("E073")
	E074 = ErrorCode("E074")
	E075 = ErrorCode("E075")
	E076 = ErrorCode("E076")
	E077 = ErrorCode("E077")
	E078 = ErrorCode("E078")
	E079 = ErrorCode("E079")
	E080 = ErrorCode("E080")
	E081 = ErrorCode("E081")
	E082 = ErrorCode("E082")
	E083 = ErrorCode("E083")
	E084 = ErrorCode("E084")
	E085 = ErrorCode("E085")
	E086 = ErrorCode("E086")
	E087 = ErrorCode("E087")
	E088 = ErrorCode("E088")
	E089 = ErrorCode("E089")
	E090 = ErrorCode("E090")
	E091 = ErrorCode("E091")
	E092 = ErrorCode("E092")
	E093 = ErrorCode("E093")
	E094 = ErrorCode("E094")
	E095 = ErrorCode("E095")
	E096 = ErrorCode("E096")
	E097 = ErrorCode("E097")
	E098 = ErrorCode("E098")
	E099 = ErrorCode("E099")
	E100 = ErrorCode("E100")
	E101 = ErrorCode("E101")
	E102 = ErrorCode("E102")
	E103 = ErrorCode("E103")
	E104 = ErrorCode("E104")
	E105 = ErrorCode("E105")
	E106 = ErrorCode("E106")
	E107 = ErrorCode("E107")
	E108 = ErrorCode("E108")
	E110 = ErrorCode("E110")
	E111 = ErrorCode("E111")
	E112 = ErrorCode("E112")
	W000 = ErrorCode("W000")
	W001 = ErrorCode("W001")
	W002 = ErrorCode("W002")
	W003 = ErrorCode("W003")
	W004 = ErrorCode("W004")
	W005 = ErrorCode("W005")
	W007 = ErrorCode("W007")
	W008 = ErrorCode("W008")
	W009 = ErrorCode("W009")
	W010 = ErrorCode("W010")
	W011 = ErrorCode("W011")
	W012 = ErrorCode("W012")
	W013 = ErrorCode("W013")
	W014 = ErrorCode("W014")
	W015 = ErrorCode("W015")
	W016 = ErrorCode("W016")
)

Variables

View Source
var OCFLValidationError1_0 = map[ErrorCode]*Error{}/* 116 elements not displayed */

OCFLValidationError1_0 contains the base error definitions for OCFL version 1.0.

View Source
var OCFLValidationError1_1 = map[ErrorCode]*Error{}/* 125 elements not displayed */

OCFLValidationError1_1 contains the base error definitions for OCFL version 1.1.

View Source
var OCFLValidationErrorMapping1_0 = map[ErrorCode]ErrorCode{
	E104: E001,
}

OCFLValidationErrorMapping1_0 maps specific error codes to their base codes for OCFL 1.0.

View Source
var OCFLValidationErrorMapping1_1 = map[ErrorCode]ErrorCode{}

OCFLValidationErrorMapping1_1 maps specific error codes to their base codes for OCFL 1.1.

Functions

This section is empty.

Types

type Error

type Error struct {
	Code         ErrorCode           // The OCFL validation code (e.g., E001).
	Description  string              // Official description from the OCFL specification.
	Ref          string              // URL to the relevant section in the OCFL specification.
	Description2 string              // Additional dynamic information about the specific occurrence.
	Context      string              // Architectural context (e.g., "storage root", "object root").
	Version      version.OCFLVersion // OCFL version the error refers to.
}

Error represents a detailed OCFL validation issue.

func GetValidationError

func GetValidationError(version version.OCFLVersion, errno ErrorCode) *Error

GetValidationError returns a base Error object for a given OCFL version and error code. If the code is not found for the version, it attempts to map it or returns an "unknown" error/warning.

func (*Error) AppendContext

func (ve *Error) AppendContext(format string, a ...any) *Error

AppendContext creates a new Error with additional information appended to the Context.

func (*Error) AppendDescription

func (ve *Error) AppendDescription(format string, a ...any) *Error

AppendDescription creates a new Error with additional information appended to Description2.

func (*Error) DetailString

func (ve *Error) DetailString() string

DetailString returns a string representation of the error including OCFL version prefix.

func (*Error) Error

func (verr *Error) Error() string

Error implements the error interface for the Error struct.

type ErrorCode

type ErrorCode string

ErrorCode represents an OCFL validation error or warning code (e.g., "E001", "W001").

type Status

type Status struct {
	Errors []*Error // List of collected errors and warnings.
}

Status collects validation errors and warnings encountered during validation.

func NewStatus

func NewStatus() *Status

NewStatus creates a new empty Status object.

func (*Status) Add

func (status *Status) Add(validationError *Error)

Add appends a validation error to the Status.

func (*Status) Compact

func (status *Status) Compact()

Compact removes duplicate errors from the Status and sorts them.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL