Repository navigation
fix(editor): validate YANG modules when loaded in the YANG modal - #117
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The YANG Modules dialog said "loaded successfully" for any text, because the WASM
loadYANGModuleonly 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.editor/internal/yangcheck(new, plain Go, so the root module'sgo test ./...runs it in CI):Checkparses the module with goyang, then processes it together with the modules already loaded.internal/yang'sModuleSetdoes 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:loadYANGModuletakes an optional third argument,loadedModulesJSON, and returnsCheck's error.editor/js:state.yangModules.#yang-load-status) that shows the result inline. The toast still appears too.editor/gottp.wasmandeditor/js/gottp.wasmare both rebuilt withmake build. They're identical, as in earlier rebuilds.Evidence
Real browser (Chrome via devtools MCP).
python3 -m http.serverservedorigin/main'seditor/and this branch'seditor/on localhost. I drove the modal's Paste and File inputs and read the text from the DOM.Before (origin/main 291675a):
module broken { … leaf a { type string;(unbalanced)broken 66 bytes— stored, no erroruser(importsbase, not loaded)broken,user— stored, no errorAfter (this branch):
brokenFailed to load YANG module 'broken': syntax error in YANG module 'broken': broken:2:0: missing 2 closing bracesthis is not yang at all… syntax error in YANG module 'unknown': unknown:1:9: not: syntax error, expected ';' or '{' …userwithoutbaseFailed to load YANG module 'user': YANG module 'user' imports module(s) not loaded: base (load them first)base, thenuserYANG module 'user' loaded successfullybase,useruser.yang,base.yang,broken.yang(that order)Loaded 2 module(s), 1 failed:/broken: syntax error … missing 2 closing bracesbase,userChecks run locally:
go vet ./...,go test ./...(withGOTTP_PYTHONpinned to TTP 0.10.1),go test -race(excludingtest/memory), staticcheck 2025.1.1, andGOOS=js GOARCH=wasm go build ./...all pass.GOOS=js GOARCH=wasm go vetineditor/wasmalso passes. There are 9 new unit tests ineditor/internal/yangcheck. TDD: they failed against a stub first.Merge Danger
Low. Nothing outside
editor/changes, and the library parse path (gottp.goloadYANGModules) is untouched.module/submodulestatement at the start of a line. Before, it matched the firstmoduleanywhere, comments included..wasmfiles show up as binary changes of about 36 MB each.🤖 Generated with Claude Code
Fixes #53