Skip to the content.

Troubleshooting

Table of Contents

Common Errors

Element Not Found

Error: Element 'xyz' is not defined in the library

Cause: The element identifier doesn’t exist in your library.

Solutions:

// Add missing element
lib.element('xyz', {
  body: 'literal',
  attributes: {}
});

Attribute Type Mismatch

Error: Invalid number format or Boolean value must be true/false, yes/no, or 1/0

Cause: Attribute value doesn’t match the expected type.

Solutions:

// Wrong
element(count: abc; enabled: maybe)

// Correct
element(count: 42; enabled: true)

Required Attribute Missing

Error: Required attribute 'xyz' is missing

Cause: An attribute marked with required: true wasn’t provided.

Solutions:

// Make optional with default
lib.element('article', {
  attributes: {
    title: { type: 'string', default: 'Untitled' }
  }
});

Undefined Constant

Error: Undefined constant: xyz

Cause: Referenced a constant that wasn’t defined.

Solutions:

// Define before use
@const(version: 1.0.0)

Version: {{version}}

Compilation Issues

File Not Found

Error: File not found: path/to/file.part.chalk

Cause: Include or main file path is incorrect.

Solutions:

// Use correct baseDir
const result = chalk.compileFile(
  'main.chalk',
  '/absolute/path/to/docs',  // baseDir
  library
);

Circular Include

Error: Circular include detected

Cause: Include files reference each other in a loop.

Solutions:

Invalid Syntax

Error: Unexpected token or parsing errors

Cause: Malformed .chalk syntax.

Solutions:

// Wrong
callout(type: warning){Content}

// Correct
callout{Content}(type: warning)

Library Issues

Element Already Exists

Error: Element 'xyz' already exists in library

Cause: Attempting to add an element with a duplicate identifier.

Solutions:

Type Not Found

Error: Type 'xyz' is not defined

Cause: Attribute references a type that doesn’t exist.

Solutions:

// Define custom type first
lib.type('url', {
  parser: (input) => {
    // validation logic
    return { ok: true, data: input };
  }
});

// Then use in attribute
lib.element('link', {
  attributes: {
    href: { type: 'url', required: true }
  }
});

Document Definition Missing

Error: Document definition is required

Cause: No document definition set in library.

Solutions:

const lib = chalk.library({
  document: {
    class: 'article',
    body: 'all',
    attributes: {
      title: { type: 'string', required: true }
    }
  }
});

Attribute Issues

Multi-Word Identifiers

Attribute and constant identifiers can contain spaces:

// Valid
element(published date: 2024-01-01)
@const(app name: My Application)

Boolean Shorthand

Boolean attributes can be written without a value to mean true:

// These are equivalent
element(enabled: true)
element(enabled)

Enum Validation

Error: Invalid enum value

Cause: Value not in the enum’s allowed values.

Solutions:

lib.createEnum({
  identifier: 'status',
  values: ['draft', 'published', 'archived']
});

// Use valid enum value
// element(status: published) ✓
// element(status: invalid) ✗

Default Values

Attributes can have default values that apply when not specified:

chalk.createAttribute('visible', 'boolean', false, true)

// Element without 'visible' will get visible: true

Getting Help

Check Documentation

Debugging Tips

  1. Enable verbose errors: Check the CompileResult.error object for detailed messages
  2. Validate incrementally: Test library definitions before full compilation
  3. Check file paths: Use absolute paths to avoid ambiguity
  4. Inspect library: Log library.elements and library.types to verify definitions
  5. Test constants: Compile a simple document with constants first

Example Debug Pattern

const result = chalk.compile(source, library);

if (!result.ok) {
  console.error('Compilation failed:');
  console.error('Error:', result.error);
  console.error('Library elements:', Object.keys(library.elements));
  console.error('Library types:', Object.keys(library.types));
}