Skip to content
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

fix(manifest): re-raise remediation error to avoid go-toml wrapping issue #915

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var ErrMissingManifestVersion = RemediationError{
// version has been specified.
var ErrUnrecognisedManifestVersion = RemediationError{
Inner: fmt.Errorf("unrecognised manifest_version found in the fastly.toml"),
Remediation: CLIUpdateRemediation,
Remediation: UnrecognisedManifestVersionRemediation,
}

// ErrIncompatibleManifestVersion means the manifest_version defined is no
Expand Down
10 changes: 6 additions & 4 deletions pkg/errors/remediation_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ var PackageSizeRemediation = strings.Join([]string{
"https://developer.fastly.com/learning/compute/#limitations-and-constraints",
}, " ")

// CLIUpdateRemediation suggests updating the installed CLI version.
var CLIUpdateRemediation = strings.Join([]string{
"Please try updating the installed CLI version using:",
"`fastly update`.",
// UnrecognisedManifestVersionRemediation suggests steps to resolve an issue
// where the project contains a manifest_version that is larger than what the
// current CLI version supports.
var UnrecognisedManifestVersionRemediation = strings.Join([]string{
"Please try updating the installed CLI version using: `fastly update`.",
"See also https://developer.fastly.com/reference/fastly-toml/ to check your fastly.toml manifest is up-to-date with the latest data model.",
BugRemediation,
}, " ")

Expand Down
13 changes: 12 additions & 1 deletion pkg/manifest/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"fmt"
"io"
"os"
"strings"

toml "github.com/pelletier/go-toml"

fsterr "github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/text"
toml "github.com/pelletier/go-toml"
)

// File represents all of the configuration parameters in the fastly.toml
Expand Down Expand Up @@ -78,6 +80,15 @@ func (f *File) Read(path string) (err error) {

err = tree.Unmarshal(f)
if err != nil {
// IMPORTANT: go-toml consumes our error type within its own.
//
// This means we need to manually parse the return error to see if it
// contains our specific error message. If we don't do this, then the
// remediation information we pass back will be lost and a generic 'bug'
// remediation (which is set by logic in main.go) is used instead.
if strings.Contains(err.Error(), fsterr.ErrUnrecognisedManifestVersion.Inner.Error()) {
err = fsterr.ErrUnrecognisedManifestVersion
}
f.logErr(err)
return err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
"strings"
"testing"

"github.com/google/go-cmp/cmp"
toml "github.com/pelletier/go-toml"

"github.com/fastly/cli/pkg/env"
fsterr "github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/manifest"
"github.com/fastly/cli/pkg/testutil"
"github.com/fastly/cli/pkg/threadsafe"
"github.com/google/go-cmp/cmp"
toml "github.com/pelletier/go-toml"
)

func TestManifest(t *testing.T) {
Expand Down Expand Up @@ -101,6 +102,9 @@ func TestManifest(t *testing.T) {

err = m.Read(path)

output := stdout.String()
t.Log(output)

// If we expect an invalid config, then assert we get the right error.
if !tc.valid {
testutil.AssertErrorContains(t, err, tc.expectedError.Error())
Expand All @@ -117,10 +121,6 @@ func TestManifest(t *testing.T) {
t.Fatalf("manifest_version '%d' doesn't match latest '%d'", m.ManifestVersion, manifest.ManifestLatestVersion)
}

output := stdout.String()

t.Log(output)

if tc.expectedOutput != "" && !strings.Contains(output, tc.expectedOutput) {
t.Fatalf("got: %s, want: %s", output, tc.expectedOutput)
}
Expand Down