forked from tektoncd/pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Label
user error
for failure PipelineRun Status
This commit labels the user errors for failed PipelineRun status. This aims to communicate explicitly with users of whether the run failed could be attributed to users' responsibility. /kind misc part of tektoncd#7276
- Loading branch information
Showing
14 changed files
with
176 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright 2023 The Tekton Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package errors | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
var ( | ||
// ErrUser is used to indicate that the user is responsible for an aerror. | ||
// See github.com/tektoncd/pipeline/blob/main/docs/pipelineruns.md#marking-off-user-errors | ||
// for more details. | ||
ErrUser = errors.New("user error") | ||
) | ||
|
||
// LabelUserError adds the "user error" mark of the error message | ||
func LabelUserError(err error) error { | ||
err = errors.Join(ErrUser, err) | ||
return err | ||
} | ||
|
||
func IsUserError(err error) bool { | ||
return errors.Is(err, ErrUser) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
Copyright 2023 The Tekton Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package errors_test | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
pipelineErrors "github.com/tektoncd/pipeline/pkg/apis/pipeline/errors" | ||
) | ||
|
||
type TestError struct{} | ||
|
||
var _ error = &TestError{} | ||
|
||
func (*TestError) Error() string { | ||
return "test error" | ||
} | ||
|
||
func TestUserErrorUnwrap(t *testing.T) { | ||
originalError := &TestError{} | ||
userError := pipelineErrors.LabelUserError(originalError) | ||
|
||
if !errors.Is(userError, pipelineErrors.ErrUser) { | ||
t.Errorf("user error expected to unwrap successfully") | ||
} | ||
} | ||
|
||
func TestResolutionErrorMessage(t *testing.T) { | ||
originalError := &TestError{} | ||
expectedErrorMessage := pipelineErrors.ErrUser.Error() + "\n" + originalError.Error() | ||
|
||
userError := pipelineErrors.LabelUserError(originalError) | ||
|
||
if userError.Error() != expectedErrorMessage { | ||
t.Errorf("user error message expected to equal to %s, got: %s", expectedErrorMessage, userError.Error()) | ||
} | ||
} | ||
|
||
func TestIsUserError(t *testing.T) { | ||
originalError := &TestError{} | ||
if pipelineErrors.IsUserError(originalError) { | ||
t.Errorf("IsUserError fails to unwrap non-user error") | ||
} | ||
|
||
userError := pipelineErrors.LabelUserError(originalError) | ||
if !pipelineErrors.IsUserError(userError) { | ||
t.Errorf("IsUserError fails to unwrap user error") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.