From 18beaf96946b948b50851679a4bfde7d4d1835cd Mon Sep 17 00:00:00 2001 From: Luca Bianconi Date: Thu, 26 Jan 2023 09:26:56 +0100 Subject: [PATCH 1/5] chore: upgrading.md wording --- docs/UPGRADING.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/UPGRADING.md b/docs/UPGRADING.md index 0d867fe05db..aada4c730b4 100644 --- a/docs/UPGRADING.md +++ b/docs/UPGRADING.md @@ -11,7 +11,6 @@ The sketch name submitted via the `sketch new` command of the CLI or the gRPC co [sketch specifications](https://arduino.github.io/arduino-cli/dev/sketch-specification). Existing sketch names violating the new constraint need to be updated. - ### `daemon` CLI command's `--ip` flag removal The `daemon` CLI command no longer allows to set a custom ip for the gRPC communication. Currently there is not enough From 85100e7a7680e3169d11a9c7e9f28ceeeee89df0 Mon Sep 17 00:00:00 2001 From: Luca Bianconi Date: Thu, 26 Jan 2023 13:54:38 +0100 Subject: [PATCH 2/5] chore: prettier --- docs/UPGRADING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/UPGRADING.md b/docs/UPGRADING.md index aada4c730b4..0d867fe05db 100644 --- a/docs/UPGRADING.md +++ b/docs/UPGRADING.md @@ -11,6 +11,7 @@ The sketch name submitted via the `sketch new` command of the CLI or the gRPC co [sketch specifications](https://arduino.github.io/arduino-cli/dev/sketch-specification). Existing sketch names violating the new constraint need to be updated. + ### `daemon` CLI command's `--ip` flag removal The `daemon` CLI command no longer allows to set a custom ip for the gRPC communication. Currently there is not enough From 7798f2512226e17edd673fee27b527bf263d7205 Mon Sep 17 00:00:00 2001 From: Luca Bianconi Date: Thu, 2 Feb 2023 12:08:16 +0100 Subject: [PATCH 3/5] fix: error messages --- commands/sketch/new.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/commands/sketch/new.go b/commands/sketch/new.go index 4e8134a5b6c..ae6a26f119f 100644 --- a/commands/sketch/new.go +++ b/commands/sketch/new.go @@ -75,14 +75,13 @@ func validateSketchName(name string) error { return &arduino.CantCreateSketchError{Cause: errors.New(tr("sketch name cannot be empty"))} } if len(name) > sketchNameMaxLength { - return &arduino.CantCreateSketchError{Cause: errors.New(tr("sketch name too long (%d characters). Maximum allowed length is %d", + return &arduino.CantCreateSketchError{Cause: errors.New(tr("sketch name too long (%[1]d characters). Maximum allowed length is %[2]d", len(name), sketchNameMaxLength))} } if !sketchNameValidationRegex.MatchString(name) { - return &arduino.CantCreateSketchError{Cause: errors.New(tr("invalid sketch name \"%s\". Required pattern %s", - name, - sketchNameValidationRegex.String()))} + 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 ".".`, + name))} } return nil } From 9b1a35d25177e938e4cbe7f2292d5cac98a79980 Mon Sep 17 00:00:00 2001 From: Luca Bianconi Date: Thu, 2 Feb 2023 12:24:55 +0100 Subject: [PATCH 4/5] fix: message escaping --- commands/sketch/new.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/sketch/new.go b/commands/sketch/new.go index ae6a26f119f..5efbee8ff48 100644 --- a/commands/sketch/new.go +++ b/commands/sketch/new.go @@ -80,7 +80,7 @@ func validateSketchName(name string) error { sketchNameMaxLength))} } if !sketchNameValidationRegex.MatchString(name) { - 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 ".".`, + 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 ".".`, name))} } return nil From b1aacff384236681613b5981eea679d190cdfe01 Mon Sep 17 00:00:00 2001 From: Luca Bianconi Date: Thu, 2 Feb 2023 12:25:08 +0100 Subject: [PATCH 5/5] test: fix behavior --- commands/sketch/new_test.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/commands/sketch/new_test.go b/commands/sketch/new_test.go index 88d2e426012..a0de66710ed 100644 --- a/commands/sketch/new_test.go +++ b/commands/sketch/new_test.go @@ -2,6 +2,7 @@ package sketch import ( "context" + "fmt" "testing" "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" @@ -11,7 +12,6 @@ import ( func Test_SketchNameWrongPattern(t *testing.T) { invalidNames := []string{ "&", - "", ".hello", "_hello", "-hello", @@ -24,11 +24,9 @@ func Test_SketchNameWrongPattern(t *testing.T) { SketchName: name, SketchDir: t.TempDir(), }) - require.NotNil(t, err) - require.Error(t, err, `Can't create sketch: invalid sketch name "%s". Required pattern %s`, - name, - sketchNameValidationRegex) + 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 ".".`, + name)) } } @@ -38,9 +36,8 @@ func Test_SketchNameEmpty(t *testing.T) { SketchName: emptyName, SketchDir: t.TempDir(), }) - require.NotNil(t, err) - require.Error(t, err, `Can't create sketch: sketch name cannot be empty`) + require.EqualError(t, err, `Can't create sketch: sketch name cannot be empty`) } func Test_SketchNameTooLong(t *testing.T) { @@ -52,11 +49,10 @@ func Test_SketchNameTooLong(t *testing.T) { SketchName: string(tooLongName), SketchDir: t.TempDir(), }) - require.NotNil(t, err) - require.Error(t, err, `Can't create sketch: sketch name too long (%d characters). Maximum allowed length is %d`, + require.EqualError(t, err, fmt.Sprintf(`Can't create sketch: sketch name too long (%d characters). Maximum allowed length is %d`, len(tooLongName), - sketchNameMaxLength) + sketchNameMaxLength)) } func Test_SketchNameOk(t *testing.T) {