Skip to content

Commit

Permalink
cli: Handle invalid board paths
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Oct 31, 2023
1 parent df1d49f commit bc7752b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion d2cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ func compile(ctx context.Context, ms *xmain.State, plugins []d2plugin.Plugin, la

board := diagram.GetBoard(boardPath)
if board == nil {
return nil, false, fmt.Errorf("Diagram with path %s not found", boardPath)
return nil, false, fmt.Errorf(`Diagram with path "%s" not found. Did you mean to specify a board like "layers.%s"?`, boardPath, boardPath)
}

boards, err := render(ctx, ms, compileDur, plugin, renderOpts, inputPath, outputPath, bundle, forceAppendix, page, ruler, board)
Expand Down
13 changes: 4 additions & 9 deletions d2target/d2target.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,24 @@ func (d *Diagram) getBoard(boardPath []string) *Diagram {
return d
}

if len(boardPath) < 2 {
return nil
}

switch head {
case "layers":
if len(boardPath) < 2 {
return nil
}
for _, b := range d.Layers {
if b.Name == boardPath[1] {
return b.getBoard(boardPath[2:])
}
}
case "scenarios":
if len(boardPath) < 2 {
return nil
}
for _, b := range d.Scenarios {
if b.Name == boardPath[1] {
return b.getBoard(boardPath[2:])
}
}
case "steps":
if len(boardPath) < 2 {
return nil
}
for _, b := range d.Steps {
if b.Name == boardPath[1] {
return b.getBoard(boardPath[2:])
Expand Down

0 comments on commit bc7752b

Please sign in to comment.