Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4c0aaa8

Browse files
authored
fix: sketch name validation error messages (#2059)
1 parent 2b8d6d7 commit 4c0aaa8

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

‎commands/sketch/new.go‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,13 @@ func validateSketchName(name string) error {
7575
return &arduino.CantCreateSketchError{Cause: errors.New(tr("sketch name cannot be empty"))}
7676
}
7777
if len(name) > sketchNameMaxLength {
78-
return &arduino.CantCreateSketchError{Cause: errors.New(tr("sketch name too long (%d characters). Maximum allowed length is %d",
78+
return &arduino.CantCreateSketchError{Cause: errors.New(tr("sketch name too long (%[1]d characters). Maximum allowed length is %[2]d",
7979
len(name),
8080
sketchNameMaxLength))}
8181
}
8282
if !sketchNameValidationRegex.MatchString(name) {
83-
return &arduino.CantCreateSketchError{Cause: errors.New(tr("invalid sketch name \"%s\". Required pattern %s",
84-
name,
85-
sketchNameValidationRegex.String()))}
83+
return &arduino.CantCreateSketchError{Cause: errors.New(tr(`invalid sketch name "%[1]s": the first character must be alphanumeric, the following ones can also contain "_", "-", and ".".`,
84+
name))}
8685
}
8786
return nil
8887
}

‎commands/sketch/new_test.go‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sketch
22

33
import (
44
"context"
5+
"fmt"
56
"testing"
67

78
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -11,7 +12,6 @@ import (
1112
func Test_SketchNameWrongPattern(t *testing.T) {
1213
invalidNames := []string{
1314
"&",
14-
"",
1515
".hello",
1616
"_hello",
1717
"-hello",
@@ -24,11 +24,9 @@ func Test_SketchNameWrongPattern(t *testing.T) {
2424
SketchName: name,
2525
SketchDir: t.TempDir(),
2626
})
27-
require.NotNil(t, err)
2827

29-
require.Error(t, err, `Can't create sketch: invalid sketch name "%s". Required pattern %s`,
30-
name,
31-
sketchNameValidationRegex)
28+
require.EqualError(t, err, fmt.Sprintf(`Can't create sketch: invalid sketch name "%s": the first character must be alphanumeric, the following ones can also contain "_", "-", and ".".`,
29+
name))
3230
}
3331
}
3432

@@ -38,9 +36,8 @@ func Test_SketchNameEmpty(t *testing.T) {
3836
SketchName: emptyName,
3937
SketchDir: t.TempDir(),
4038
})
41-
require.NotNil(t, err)
4239

43-
require.Error(t, err, `Can't create sketch: sketch name cannot be empty`)
40+
require.EqualError(t, err, `Can't create sketch: sketch name cannot be empty`)
4441
}
4542

4643
func Test_SketchNameTooLong(t *testing.T) {
@@ -52,11 +49,10 @@ func Test_SketchNameTooLong(t *testing.T) {
5249
SketchName: string(tooLongName),
5350
SketchDir: t.TempDir(),
5451
})
55-
require.NotNil(t, err)
5652

57-
require.Error(t, err, `Can't create sketch: sketch name too long (%d characters). Maximum allowed length is %d`,
53+
require.EqualError(t, err, fmt.Sprintf(`Can't create sketch: sketch name too long (%d characters). Maximum allowed length is %d`,
5854
len(tooLongName),
59-
sketchNameMaxLength)
55+
sketchNameMaxLength))
6056
}
6157

6258
func Test_SketchNameOk(t *testing.T) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /