Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
3505fb48
Commit
3505fb48
authored
Jun 18, 2015
by
Satnam Singh
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9803 from satnam6502/execessive
Improve error output of kubectl update
parents
790ca234
d69e0b5e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
1 deletion
+53
-1
update.go
pkg/kubectl/cmd/update.go
+1
-1
helpers.go
pkg/kubectl/cmd/util/helpers.go
+52
-0
No files found.
pkg/kubectl/cmd/update.go
View file @
3505fb48
...
...
@@ -48,7 +48,7 @@ func NewCmdUpdate(f *cmdutil.Factory, out io.Writer) *cobra.Command {
Example
:
update_example
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
err
:=
RunUpdate
(
f
,
out
,
cmd
,
args
,
filenames
)
cmdutil
.
Check
Err
(
err
)
cmdutil
.
Check
CustomErr
(
"Update failed"
,
err
)
},
}
usage
:=
"Filename, directory, or URL to file to use to update the resource."
...
...
pkg/kubectl/cmd/util/helpers.go
View file @
3505fb48
...
...
@@ -83,6 +83,58 @@ func checkErr(err error, handleErr func(string)) {
handleErr
(
msg
)
}
// CheckCustomErr is like CheckErr except a custom prefix error
// string may be provied to help produce more specific error messages.
// For example, for the update failed case this function could be called
// with:
// cmdutil.CheckCustomErr("Update failed", err)
// This function supresses the detailed output that is produced by CheckErr
// and specifically the field is erased and the error message has the details
// of the spec removed. Unfortunately, what starts off as a detail message is
// a sperate field ends up being concatentated into one string which contains
// the spec and the detail string. To avoid significant refactoring of the error
// data structures we just extract the required detail string by looking for it
// after "}': " which is horrible but expedient.
func
CheckCustomErr
(
customPrefix
string
,
err
error
)
{
checkCustomErr
(
customPrefix
,
err
,
fatal
)
}
func
checkCustomErr
(
customPrefix
string
,
err
error
,
handleErr
func
(
string
))
{
if
err
==
nil
{
return
}
if
errors
.
IsInvalid
(
err
)
{
details
:=
err
.
(
*
errors
.
StatusError
)
.
Status
()
.
Details
for
i
:=
range
details
.
Causes
{
c
:=
&
details
.
Causes
[
i
]
s
:=
strings
.
Split
(
c
.
Message
,
"}': "
)
if
len
(
s
)
==
2
{
c
.
Message
=
s
[
1
]
c
.
Field
=
""
}
}
prefix
:=
fmt
.
Sprintf
(
"%s"
,
customPrefix
)
errs
:=
statusCausesToAggrError
(
details
.
Causes
)
handleErr
(
MultilineError
(
prefix
,
errs
))
}
// handle multiline errors
if
clientcmd
.
IsConfigurationInvalid
(
err
)
{
handleErr
(
MultilineError
(
"Error in configuration: "
,
err
))
}
if
agg
,
ok
:=
err
.
(
utilerrors
.
Aggregate
);
ok
&&
len
(
agg
.
Errors
())
>
0
{
handleErr
(
MultipleErrors
(
""
,
agg
.
Errors
()))
}
msg
,
ok
:=
StandardErrorMessage
(
err
)
if
!
ok
{
msg
=
fmt
.
Sprintf
(
"error: %s
\n
"
,
err
.
Error
())
}
handleErr
(
msg
)
}
func
statusCausesToAggrError
(
scs
[]
api
.
StatusCause
)
utilerrors
.
Aggregate
{
errs
:=
make
([]
error
,
len
(
scs
))
for
i
,
sc
:=
range
scs
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment