Documentation
¶
Index ¶
- Variables
- func Format(d Diagnostic) string
- func FormatAll(ds DiagnosticSet) string
- type Diagnostic
- type DiagnosticBuilder
- func (b *DiagnosticBuilder) Build() Diagnostic
- func (b *DiagnosticBuilder) Column(col int) *DiagnosticBuilder
- func (b *DiagnosticBuilder) File(file string) *DiagnosticBuilder
- func (b *DiagnosticBuilder) Hint(hint string) *DiagnosticBuilder
- func (b *DiagnosticBuilder) Line(line int) *DiagnosticBuilder
- func (b *DiagnosticBuilder) SourceLine(line string) *DiagnosticBuilder
- func (b *DiagnosticBuilder) Underline(start, length int) *DiagnosticBuilder
- type DiagnosticSet
- type ErrorCode
- type ErrorInfo
Constants ¶
This section is empty.
Variables ¶
var Registry = map[ErrorCode]ErrorInfo{ ErrDynamicValue: { Code: ErrDynamicValue, Title: "schema values must use literal values for static analysis", HelpURL: "forge help E001", }, ErrUnsupportedType: { Code: ErrUnsupportedType, Title: "unsupported field type", HelpURL: "forge help E002", }, ErrInvalidFieldName: { Code: ErrInvalidFieldName, Title: "invalid field name", HelpURL: "forge help E003", }, ErrMissingArgument: { Code: ErrMissingArgument, Title: "required argument missing", HelpURL: "forge help E004", }, ErrInvalidModifierValue: { Code: ErrInvalidModifierValue, Title: "invalid modifier value", HelpURL: "forge help E005", }, ErrDuplicateField: { Code: ErrDuplicateField, Title: "duplicate field name", HelpURL: "forge help E100", }, ErrInvalidEnumDefault: { Code: ErrInvalidEnumDefault, Title: "enum default value not in allowed values", HelpURL: "forge help E101", }, ErrMissingPrimaryKey: { Code: ErrMissingPrimaryKey, Title: "resource missing primary key", HelpURL: "forge help E102", }, }
Registry maps error codes to their metadata.
Functions ¶
func Format ¶
func Format(d Diagnostic) string
Format renders a single diagnostic in Rust-style format.
Output structure:
error[E001]: schema values must use literal values for static analysis
--> resources/product/schema.go:12:34
|
12 | schema.String("Title").MaxLen(maxLen),
| ^^^^^^
|
= hint: Forge schemas must use literal values for static analysis.
Found variable 'maxLen' — use a constant or literal instead.
= help: Run `forge help E001` for more information
func FormatAll ¶
func FormatAll(ds DiagnosticSet) string
FormatAll renders all diagnostics in a DiagnosticSet with separators.
Types ¶
type Diagnostic ¶
type Diagnostic struct {
Code ErrorCode // Error code (e.g., "E001")
Message string // Human-readable error description
Hint string // Suggestion for fixing the error
File string // Source file path
Line int // 1-based line number
Column int // 1-based column number
SourceLine string // The actual line of source code
UnderlineStart int // Column where underline begins (0-based within SourceLine)
UnderlineLen int // Length of underline (number of chars to underline)
}
Diagnostic represents a rich error with source context and suggestions.
type DiagnosticBuilder ¶
type DiagnosticBuilder struct {
// contains filtered or unexported fields
}
DiagnosticBuilder provides a fluent API for constructing diagnostics.
func NewDiagnostic ¶
func NewDiagnostic(code ErrorCode, msg string) *DiagnosticBuilder
NewDiagnostic creates a new diagnostic builder.
func (*DiagnosticBuilder) Build ¶
func (b *DiagnosticBuilder) Build() Diagnostic
Build returns the constructed Diagnostic.
func (*DiagnosticBuilder) Column ¶
func (b *DiagnosticBuilder) Column(col int) *DiagnosticBuilder
Column sets the column number (1-based).
func (*DiagnosticBuilder) File ¶
func (b *DiagnosticBuilder) File(file string) *DiagnosticBuilder
File sets the source file path.
func (*DiagnosticBuilder) Hint ¶
func (b *DiagnosticBuilder) Hint(hint string) *DiagnosticBuilder
Hint sets a suggestion for fixing the error.
func (*DiagnosticBuilder) Line ¶
func (b *DiagnosticBuilder) Line(line int) *DiagnosticBuilder
Line sets the line number (1-based).
func (*DiagnosticBuilder) SourceLine ¶
func (b *DiagnosticBuilder) SourceLine(line string) *DiagnosticBuilder
SourceLine sets the actual source code line.
func (*DiagnosticBuilder) Underline ¶
func (b *DiagnosticBuilder) Underline(start, length int) *DiagnosticBuilder
Underline sets the underline position and length (0-based within source line).
type DiagnosticSet ¶
type DiagnosticSet struct {
Diagnostics []Diagnostic
}
DiagnosticSet is a collection of diagnostics. It implements the error interface so it can be returned as an error.
func (DiagnosticSet) Count ¶
func (ds DiagnosticSet) Count() int
Count returns the number of diagnostics in the set.
func (DiagnosticSet) Error ¶
func (ds DiagnosticSet) Error() string
Error implements the error interface. Returns a formatted string of all diagnostics.
func (DiagnosticSet) HasErrors ¶
func (ds DiagnosticSet) HasErrors() bool
HasErrors returns true if the set contains any diagnostics.
type ErrorCode ¶
type ErrorCode string
ErrorCode is a unique identifier for each error type.
const ( ErrDynamicValue ErrorCode = "E001" // Schema uses variable instead of literal ErrUnsupportedType ErrorCode = "E002" // Field type not supported ErrInvalidFieldName ErrorCode = "E003" // Field name invalid ErrMissingArgument ErrorCode = "E004" // Required argument missing ErrInvalidModifierValue ErrorCode = "E005" // Modifier value invalid )
Parser errors (E0xx range)