Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beaver
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
orus-io
beaver
Commits
74d8dfce5c37
Commit
74d8dfce5c37
authored
2 years ago
by
steeve.chailloux
Browse files
Options
Downloads
Patches
Plain Diff
runCommand must always return a file to avoid nil pointer exception
parent
55feb6cff2cd
No related branches found
No related tags found
1 merge request
!2
runCommand must always return a file to avoid nil pointer exception
Pipeline
#41532
passed
2 years ago
Stage: test
Stage: lint
Stage: build
Stage: upload
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
runner/main.go
+13
-13
13 additions, 13 deletions
runner/main.go
with
13 additions
and
13 deletions
runner/main.go
+
13
−
13
View file @
74d8dfce
...
...
@@ -223,8 +223,20 @@
return
cmds
,
nil
}
func
(
r
*
Runner
)
runCommand
(
tmpDir
,
name
string
,
cmd
*
cmd
.
Cmd
)
(
*
os
.
File
,
error
)
{
tmpFile
,
err
:=
ioutil
.
TempFile
(
tmpDir
,
fmt
.
Sprintf
(
"compiled-%s-*.yaml"
,
name
))
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot create compiled file: %w"
,
err
)
}
defer
func
()
{
if
err
:=
tmpFile
.
Close
();
err
!=
nil
{
r
.
config
.
Logger
.
Err
(
err
)
.
Str
(
"temp file"
,
tmpFile
.
Name
())
.
Msg
(
"failed to close temp file"
)
}
}()
if
r
.
config
.
DryRun
{
r
.
config
.
Logger
.
Info
()
.
Str
(
"command"
,
cmd
.
Name
)
.
Str
(
"args"
,
strings
.
Join
(
cmd
.
Args
,
" "
))
.
Msg
(
"would run command"
)
...
...
@@ -226,9 +238,9 @@
if
r
.
config
.
DryRun
{
r
.
config
.
Logger
.
Info
()
.
Str
(
"command"
,
cmd
.
Name
)
.
Str
(
"args"
,
strings
.
Join
(
cmd
.
Args
,
" "
))
.
Msg
(
"would run command"
)
return
n
il
,
nil
return
tmpF
il
e
,
nil
}
stdOut
,
stdErr
,
err
:=
RunCMD
(
cmd
)
if
err
!=
nil
{
...
...
@@ -243,18 +255,6 @@
fmt
.
Printf
(
"
\n
%s
\n\n
"
,
strings
.
Join
(
stdErr
,
"
\n
"
))
return
nil
,
fmt
.
Errorf
(
"failed to run command: %w"
,
err
)
}
tmpFile
,
err
:=
ioutil
.
TempFile
(
tmpDir
,
fmt
.
Sprintf
(
"compiled-%s-*.yaml"
,
name
))
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot create compiled file: %w"
,
err
)
}
defer
func
()
{
if
err
:=
tmpFile
.
Close
();
err
!=
nil
{
r
.
config
.
Logger
.
Err
(
err
)
.
Str
(
"temp file"
,
tmpFile
.
Name
())
.
Msg
(
"failed to close temp file"
)
}
}()
if
_
,
err
:=
tmpFile
.
WriteString
(
strings
.
Join
(
stdOut
,
"
\n
"
));
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot write compiled file: %w"
,
err
)
}
...
...
This diff is collapsed.
Click to expand it.
Florent Aide
@florent.aide
mentioned in commit
b1cc31cbb0ab
·
2 years ago
mentioned in commit
b1cc31cbb0ab
mentioned in commit b1cc31cbb0ab893130032b4895dfdf6545cfe9f1
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment