Skip to content

fix(editor): validate YANG modules when loaded in the YANG modal - #117

Merged
roc-ops merged 1 commit into
mainfrom
fix/53-yang-modal-validate
Nov 28, 2026
Merged

roc-ops merged 1 commit into
mainfrom
fix/53-yang-modal-validate

Conversation

@roc-ops

@roc-ops roc-ops commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Summary

The YANG Modules dialog said "loaded successfully" for any text, because the WASM loadYANGModule only wrapped it in JSON. Now the module gets parsed and resolved when you load it. A module that fails is rejected in the dialog and is not stored.

before:  paste ──► wrap in JSON ──► "loaded successfully" ──► stored ──► … Process ──► whole parse fails
after:   paste ──► yangcheck.Check(name, content, loadedModules)
                     ├─ goyang Parse fails         ──► "syntax error in YANG module 'x': x:2:0: missing 2 closing braces"
                     ├─ Process: no such module    ──► "YANG module 'x' imports module(s) not loaded: base (load them first)"
                     ├─ Process: other new errors  ──► "YANG module 'x' is invalid: x:1:54: unknown type: …"
                     └─ ok                         ──► stored, "loaded successfully"
  • editor/internal/yangcheck (new, plain Go, so the root module's go test ./... runs it in CI): Check parses the module with goyang, then processes it together with the modules already loaded. internal/yang's ModuleSet does the same at parse time, so imports resolve against loaded modules in any order. Errors that the loaded modules already produce on their own get filtered out by diffing, so the new module isn't blamed for them. Reloading a module under the same name counts as a replacement, not a duplicate.
  • editor/wasm/main.go: loadYANGModule takes an optional third argument, loadedModulesJSON, and returns Check's error.
  • editor/js:
    • The bridge passes state.yangModules.
    • The modal has a new status line (#yang-load-status) that shows the result inline. The toast still appears too.
    • Only modules that pass are stored.
    • On failure the pasted text and URL input are kept so you can fix them.
    • A multi-file selection loads in dependency order: failed files are retried while any file in the set still loads.
  • editor/gottp.wasm and editor/js/gottp.wasm are both rebuilt with make build. They're identical, as in earlier rebuilds.

Evidence

Real browser (Chrome via devtools MCP). python3 -m http.server served origin/main's editor/ and this branch's editor/ on localhost. I drove the modal's Paste and File inputs and read the text from the DOM.

Before (origin/main 291675a):

Action Loaded Modules list
paste module broken { … leaf a { type string; (unbalanced) broken 66 bytes — stored, no error
paste user (imports base, not loaded) broken, user — stored, no error

After (this branch):

Action Status line Stored
paste unbalanced broken Failed to load YANG module 'broken': syntax error in YANG module 'broken': broken:2:0: missing 2 closing braces none (paste kept)
paste this is not yang at all … syntax error in YANG module 'unknown': unknown:1:9: not: syntax error, expected ';' or '{' … none
paste user without base Failed to load YANG module 'user': YANG module 'user' imports module(s) not loaded: base (load them first) none
paste base, then user YANG module 'user' loaded successfully base, user
file input: user.yang, base.yang, broken.yang (that order) Loaded 2 module(s), 1 failed: / broken: syntax error … missing 2 closing braces base, user

Checks run locally: go vet ./..., go test ./... (with GOTTP_PYTHON pinned to TTP 0.10.1), go test -race (excluding test/memory), staticcheck 2025.1.1, and GOOS=js GOARCH=wasm go build ./... all pass. GOOS=js GOARCH=wasm go vet in editor/wasm also passes. There are 9 new unit tests in editor/internal/yangcheck. TDD: they failed against a stub first.

Merge Danger

Low. Nothing outside editor/ changes, and the library parse path (gottp.go loadYANGModules) is untouched.

  • Behaviour change: loading a module that imports one not yet loaded is now rejected. Load the dependency first, or select both files together; the multi-file loader handles the order.
  • Not changed: restoring a saved workspace still keeps every stored module even if it no longer validates, same as before.
  • Module-name extraction now anchors to a module/submodule statement at the start of a line. Before, it matched the first module anywhere, comments included.
  • Large binaries: both .wasm files show up as binary changes of about 36 MB each.

🤖 Generated with Claude Code

Fixes #53

The WASM loadYANGModule only wrapped the module text in JSON, so the
YANG Modules dialog said "loaded successfully" for invalid YANG and the
error surfaced later as a whole-parse failure.

loadYANGModule now runs the new editor/internal/yangcheck.Check, which
parses the module with goyang and processes it together with the
already-loaded modules (as internal/yang's ModuleSet does at parse
time). Syntax errors, imports of modules that are not loaded, and other
processing errors are returned; errors owned only by other loaded
modules are not blamed on the new one.

The dialog shows the result in a status line, stores only modules that
pass, keeps pasted/URL input on failure, and loads multi-file selections
in dependency order. Rebuilt both committed gottp.wasm copies.

Fixes #53

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@roc-ops
roc-ops merged commit 85ba916 into main Nov 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editor: YANG modal reports "loaded successfully" for invalid YANG

1 participant