Skip to content

Fix path in error messages on sketch loading #1805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions arduino/sketch/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func New(path *paths.Path) (*Sketch, error) {
}

path = path.Canonical()
if exist, err := path.ExistCheck(); err != nil {
return nil, fmt.Errorf("%s: %s", tr("sketch path is not valid"), err)
} else if !exist {
return nil, fmt.Errorf("%s: %s", tr("no such file or directory"), path)
}
if _, validIno := globals.MainFileValidExtensions[path.Ext()]; validIno && !path.IsDir() {
path = path.Parent()
}
Expand Down
4 changes: 2 additions & 2 deletions arduino/sketch/sketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestNewSketchWrongMain(t *testing.T) {
sketch, err = New(mainFilePath)
require.Nil(t, sketch)
require.Error(t, err)
expectedError = fmt.Sprintf("main file missing from sketch: %s", expectedMainFile)
expectedError = fmt.Sprintf("no such file or directory: %s", expectedMainFile)
require.Contains(t, err.Error(), expectedError)
}

Expand Down Expand Up @@ -143,7 +143,7 @@ func TestNewSketchCasingWrong(t *testing.T) {
_, ok := skerr.(*InvalidSketchFolderNameError)
assert.False(t, ok)
sketchPath, _ = sketchPath.Abs()
expectedError := fmt.Sprintf("main file missing from sketch: %s", sketchPath.Join(sketchPath.Base()+".ino"))
expectedError := fmt.Sprintf("no such file or directory: %s", sketchPath)
require.EqualError(t, skerr, expectedError)
}
}
Expand Down
30 changes: 21 additions & 9 deletions test/test_compile_part_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,30 @@ def test_compile_error_message(run_command, working_dir):
# Run a batch of bogus compile in a temp dir to check the error messages
with tempfile.TemporaryDirectory() as tmp_dir:
tmp = Path(tmp_dir)
res = run_command(["compile", "-b", "arduino:avr:uno", tmp / "ABCDEF"])
abcdef = tmp / "ABCDEF"
res = run_command(["compile", "-b", "arduino:avr:uno", abcdef])
assert res.failed
assert "missing" in res.stderr
assert "ABCDEF" in res.stderr
res = run_command(["compile", "-b", "arduino:avr:uno", tmp / "ABCDEF" / "ABCDEF.ino"])
assert "no such file or directory:" in res.stderr
res = run_command(["compile", "-b", "arduino:avr:uno", abcdef / "ABCDEF.ino"])
assert res.failed
assert "missing" in res.stderr
assert "ABCDEF" in res.stderr
res = run_command(["compile", "-b", "arduino:avr:uno", tmp / "ABCDEF" / "QWERTY"])
assert "no such file or directory:" in res.stderr
res = run_command(["compile", "-b", "arduino:avr:uno", abcdef / "QWERTY"])
assert res.failed
assert "missing" in res.stderr
assert "QWERTY" in res.stderr
assert "no such file or directory:" in res.stderr

abcdef.mkdir()
res = run_command(["compile", "-b", "arduino:avr:uno", abcdef])
assert res.failed
assert "main file missing from sketch:" in res.stderr
res = run_command(["compile", "-b", "arduino:avr:uno", abcdef / "ABCDEF.ino"])
assert res.failed
assert "no such file or directory:" in res.stderr

qwerty_ino = abcdef / "QWERTY.ino"
qwerty_ino.touch()
res = run_command(["compile", "-b", "arduino:avr:uno", qwerty_ino])
assert res.failed
assert "main file missing from sketch:" in res.stderr


def test_compile_with_simple_sketch(run_command, data_dir, working_dir):
Expand Down