Skip to content

Commit

Permalink
change to error
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Jan 8, 2025
1 parent 34ebc5d commit 6e29f0e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 589 deletions.
5 changes: 0 additions & 5 deletions d2compiler/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ func (c *compiler) compileBoardsField(g *d2graph.Graph, ir *d2ir.Map, fieldName
g2.Parent = g
g2.AST = m.AST().(*d2ast.Map)
g2.BaseAST = findFieldAST(g.BaseAST, f)
// We cannot find the AST from the graph's base ast, which means it must be imported
// Then the base AST continues to be the one with the import
if g2.BaseAST == nil {
g2.BaseAST = g.BaseAST
}
c.compileBoard(g2, m)
if f.Primary() != nil {
c.compileLabel(&g2.Root.Attributes, f)
Expand Down
17 changes: 8 additions & 9 deletions d2oracle/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func Set(g *d2graph.Graph, boardPath []string, key string, tag, value *string) (

boardG := g
baseAST := g.AST
// b, _ := json.MarshalIndent(g, "", " ")
// println("\033[1;31m--- DEBUG:", string(b), "\033[m")

if len(boardPath) > 0 {
// When compiling a nested board, we can read from boardG but only write to baseBoardG
Expand All @@ -101,6 +103,9 @@ func Set(g *d2graph.Graph, boardPath []string, key string, tag, value *string) (
}
// TODO beter name
baseAST = boardG.BaseAST
if baseAST == nil {
return nil, fmt.Errorf("board %v cannot be modified through this file", boardPath)
}
}

err = _set(boardG, baseAST, key, tag, value)
Expand All @@ -109,16 +114,10 @@ func Set(g *d2graph.Graph, boardPath []string, key string, tag, value *string) (
}

if len(boardPath) > 0 {
// The baseAST may not correspond with the board path if the baseAST if the import
// In which case keep trying less nested board paths until it gets to the one with the import
// See test Set/import/10
for i := len(boardPath); i > 0; i-- {
replaced := ReplaceBoardNode(g.AST, baseAST, boardPath[:i])
if replaced {
return recompile(g)
}
replaced := ReplaceBoardNode(g.AST, baseAST, boardPath)
if !replaced {
return nil, fmt.Errorf("board %v AST not found", boardPath)
}
return nil, fmt.Errorf("board %v AST not found", boardPath)
}

return recompile(g)
Expand Down
10 changes: 1 addition & 9 deletions d2oracle/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2487,15 +2487,7 @@ layers: {
boardPath: []string{"man", "1"},
key: `asdf.link`,
value: go2.Pointer(`_._`),
exp: `heyn
layers: {
man: {
...@meow
asdf.link: _._
}
}
`,
expErr: `failed to set "asdf.link" to "\"_._\"": board [man 1] cannot be modified through this file`,
},
{
name: "label-near/1",
Expand Down
Loading

0 comments on commit 6e29f0e

Please sign in to comment.