Skip to content

Show error for reserved keywords #2082

@siddhantk232

Description

@siddhantk232
-- record template:
string name:

-- template t:
name: something

-- Test:
name: $t.name

-- component Test:
string name:

-- ftd.text: $Test.name

-- end: Test

This code fails with a weird error:

fastn-Error: path: featured/, PackageError { message: "failed to parse ASTError(Parse { message: \"Expect Variable value string, found: `Record { name: \\\"t\\\", caption: None, headers: HeaderValues([HeaderValue { key: \\\"name\\\", mutable: false, value: String { value: \\\"something\\\", line_number: 5, source: Default, condition: None }, line_number: 5, kind: None, condition: None }]), body: None, values: [], line_number: 4, condition: None }`\", doc_id: \"fastn.com/featured\", line_number: 4 })" }

The parser is confused as it's trying to interpret the record template as string. The template keyword is introduced recently in #2075.

Ideally the parser should check for reserved keywords during declaration and return an error that is more understandable to the user.

Possible solution

Check section.name against a set of reserved keywords before continue parsing in https://github.com/fastn-stack/fastn/blob/main/ftd-ast/src/ast.rs#L67

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions