Skip to content

Commit 944310f

Browse files
committed
Even better error messages
1 parent c2f3a51 commit 944310f

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

Diff for: arduino/sketch/sketch.go

+5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ func New(path *paths.Path) (*Sketch, error) {
6464
}
6565

6666
path = path.Canonical()
67+
if exist, err := path.ExistCheck(); err != nil {
68+
return nil, fmt.Errorf("%s: %s", tr("sketch path is not valid"), err)
69+
} else if !exist {
70+
return nil, fmt.Errorf("%s: %s", tr("no such file or directory"), path)
71+
}
6772
if _, validIno := globals.MainFileValidExtensions[path.Ext()]; validIno && !path.IsDir() {
6873
path = path.Parent()
6974
}

Diff for: arduino/sketch/sketch_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func TestNewSketchWrongMain(t *testing.T) {
108108
sketch, err = New(mainFilePath)
109109
require.Nil(t, sketch)
110110
require.Error(t, err)
111-
expectedError = fmt.Sprintf("main file missing from sketch: %s", expectedMainFile)
111+
expectedError = fmt.Sprintf("no such file or directory: %s", expectedMainFile)
112112
require.Contains(t, err.Error(), expectedError)
113113
}
114114

@@ -143,7 +143,7 @@ func TestNewSketchCasingWrong(t *testing.T) {
143143
_, ok := skerr.(*InvalidSketchFolderNameError)
144144
assert.False(t, ok)
145145
sketchPath, _ = sketchPath.Abs()
146-
expectedError := fmt.Sprintf("main file missing from sketch: %s", sketchPath.Join(sketchPath.Base()+".ino"))
146+
expectedError := fmt.Sprintf("no such file or directory: %s", sketchPath)
147147
require.EqualError(t, skerr, expectedError)
148148
}
149149
}

Diff for: test/test_compile_part_1.py

+21-9
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,30 @@ def test_compile_error_message(run_command, working_dir):
4747
# Run a batch of bogus compile in a temp dir to check the error messages
4848
with tempfile.TemporaryDirectory() as tmp_dir:
4949
tmp = Path(tmp_dir)
50-
res = run_command(["compile", "-b", "arduino:avr:uno", tmp / "ABCDEF"])
50+
abcdef = tmp / "ABCDEF"
51+
res = run_command(["compile", "-b", "arduino:avr:uno", abcdef])
5152
assert res.failed
52-
assert "missing" in res.stderr
53-
assert "ABCDEF" in res.stderr
54-
res = run_command(["compile", "-b", "arduino:avr:uno", tmp / "ABCDEF" / "ABCDEF.ino"])
53+
assert "no such file or directory:" in res.stderr
54+
res = run_command(["compile", "-b", "arduino:avr:uno", abcdef / "ABCDEF.ino"])
5555
assert res.failed
56-
assert "missing" in res.stderr
57-
assert "ABCDEF" in res.stderr
58-
res = run_command(["compile", "-b", "arduino:avr:uno", tmp / "ABCDEF" / "QWERTY"])
56+
assert "no such file or directory:" in res.stderr
57+
res = run_command(["compile", "-b", "arduino:avr:uno", abcdef / "QWERTY"])
5958
assert res.failed
60-
assert "missing" in res.stderr
61-
assert "QWERTY" in res.stderr
59+
assert "no such file or directory:" in res.stderr
60+
61+
abcdef.mkdir()
62+
res = run_command(["compile", "-b", "arduino:avr:uno", abcdef])
63+
assert res.failed
64+
assert "main file missing from sketch:" in res.stderr
65+
res = run_command(["compile", "-b", "arduino:avr:uno", abcdef / "ABCDEF.ino"])
66+
assert res.failed
67+
assert "no such file or directory:" in res.stderr
68+
69+
qwertyIno = abcdef / "QWERTY.ino"
70+
qwertyIno.touch()
71+
res = run_command(["compile", "-b", "arduino:avr:uno", qwertyIno])
72+
assert res.failed
73+
assert "main file missing from sketch:" in res.stderr
6274

6375

6476
def test_compile_with_simple_sketch(run_command, data_dir, working_dir):

0 commit comments

Comments
 (0)