Masterbelt

masterbelt/masterbelt

Diagnostics

Synced from main@9490864MarkdownSource

#Diagnostics

#Shape

  • A diagnostic has a code, severity, optional source span, and typed arguments.
  • Source spans identify a file name, start position, and end position.
  • Positions are zero-based and include byte offset, line, and column.

#Message Localization

  • Every user-visible diagnostic message must be defined in a locale catalog.
  • Implementation code must not embed user-visible diagnostic message strings.
  • Diagnostic codes, constants, severities, and argument schemas are defined in a diagnostic registry.
  • Locale catalogs contain only diagnostic code and localized message template columns.
  • The English locale is required during development.
  • Other locales, including Japanese, must be addable without changing diagnostic call sites.
  • Diagnostics store code, severity, span, and typed arguments.
  • Diagnostic reporters render localized messages from the locale catalog.
  • Diagnostics that are not tied to source text may omit the source span.
  • Catalog templates use {name} placeholders for arguments.
  • All placeholders used by a localized message must be declared by that diagnostic code's argument schema.
  • All diagnostic codes must have an English message.
  • Missing messages, unknown message codes, or mismatched placeholders are errors in generation or tests.
  • Diagnostic code catalogs are stable user-visible contracts.
  • Adding, removing, or renaming a diagnostic code is a user-visible behavior change.
  • At this stage, diagnostic argument schemas only define string arguments.

#Reporters

  • Text reporters write one localized diagnostic message per line.
  • JSON reporters write an object with a diagnostics array.
  • Each JSON diagnostic entry contains code, severity, message, optional span, and optional args.
  • When there are no diagnostics, JSON reporters write an empty diagnostics array.

#Severities

  • error: the source cannot be accepted for the requested operation.
  • warning: the source can be accepted, but the behavior should be reviewed.
  • info: informational output.
  • hint: editor-oriented guidance.

#Master Validation Diagnostics

The master validation feature registers the following diagnostic codes.

#Validator Evaluation

CodeSeverityMeaningArguments
masterbelt.validation.assert_failedconfigured (default error)An assert condition evaluated false. The span is the condition expression.master, validator, scope (each/all), record, expr
masterbelt.validation.evaluation_failederrorA validation rule body raised a hard evaluation error.master, validator, scope, detail

masterbelt.validation.assert_failed is emitted at the severity resolved from project configuration: the default is error, and a (master, validator) override to warning is reflected in the emitted diagnostic. The master argument is the entrypoint-visible master path; the record argument is the failing record's primary-key description for an each failure and <table> for an all failure; expr is the condition's source text.

#Validator Configuration

CodeSeverityMeaningArguments
masterbelt.validation.config_unknown_mastererrorA validators config key names a master that does not exist.master
masterbelt.validation.config_unknown_validatorerrorA validators config key names a validator that does not exist on a known master.master, validator
masterbelt.validation.config_invalid_severityerrorA validators severity is not error or warning.master, validator, severity
masterbelt.validation.ambiguous_mastererrorA master is re-exported from the entry module under more than one name, so no config path identifies it unambiguously; its validators are skipped.master, aliases

A master that the entry module neither declares nor re-exports has no entrypoint-visible config path, so its validators are out of scope and run no diagnostics.

#Checker

CodeSeverityMeaningArguments
masterbelt.checker.validator_duplicateerrorA duplicate validator id within a master.master, name
masterbelt.checker.assert_outside_validationerrorassert used outside a validation block.
masterbelt.checker.return_in_validationerrorreturn used inside a validation block.
masterbelt.checker.assert_condition_non_boolerrorAn assert condition is not bool.actual

#Parser

CodeSeverityMeaning
masterbelt.parser.assert_missing_conditionerrorAn assert statement has no condition expression.
masterbelt.parser.master_validation_group_missing_scopeerrorA validation group is missing its each / all scope.
masterbelt.parser.master_validation_rule_missing_nameerrorA validate rule is missing its identifier.
masterbelt.parser.master_validation_rule_missing_bodyerrorA validate rule is missing its body block.
masterbelt.parser.unexpected_master_validation_nodeerrorAn unexpected node appeared inside a validation section.

A duplicate validation section within a master reuses the existing masterbelt.parser.master_section_duplicate code.

#Scope Diagnostics

The master scope section and the SQLite indexed-scope inference contribute the following diagnostics.

#Parser

CodeSeverityMeaning
masterbelt.parser.master_scope_missing_nameerrorA scope declaration has no name.
masterbelt.parser.master_scope_missing_bodyerrorA scope declaration has no body.

#Checker

CodeSeverityMeaningArguments
masterbelt.checker.duplicate_scopeerrorA duplicate scope name within one master.master, name
masterbelt.checker.scope_name_conflicterrorA scope name collides with a relation method, nested master, static, function, or const.master, name
masterbelt.checker.scope_return_type_mismatcherrorA scope body returns something other than the declaring master's Relation<M>.master, actual
masterbelt.checker.scope_missing_returnerrorA block-body scope has no return.master, name
masterbelt.checker.scope_forbidden_effecterrorA scope body or query callback inherits failable / cancellable / asyncable.master, name, effect
masterbelt.checker.cyclic_scopeerrorA scope references itself directly or transitively. The span is the cycle-closing call's callee.master, name
masterbelt.checker.scope_unknown_fielderrorA query callback references a field the record does not declare.master, field

Some scope misuse reuses existing diagnostics rather than a scope-specific code: declaring or assigning self is reported as masterbelt.parser.reserved_identifier because self is lexically reserved (see lexical.md); a scope call with the wrong argument count or types is reported through the general call diagnostics (masterbelt.checker.call_argument_count_mismatch, masterbelt.checker.call_argument_type_mismatch); and a scope call on a receiver that does not expose the scope is reported as masterbelt.checker.unknown_member.

#SQLite Index Inference

CodeSeverityMeaningArguments
masterbelt.scope.index_inference_failedwarningAn indexed scope could not be fully turned into a secondary index; any inferable part is still generated.master, scope
masterbelt.scope.index_generatedinfoA secondary index was generated from an indexed scope.master, scope, index
Specification