mirror of
https://gitlab.com/TECHNOFAB/nixtest.git
synced 2025-12-12 10:10:09 +01:00
fix: handle nix build errors gracefully
This commit is contained in:
parent
abac8aaf3e
commit
6e17ec8838
1 changed files with 8 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -54,12 +55,16 @@ func buildAndParse(variable string) (any, error) {
|
||||||
"--print-out-paths",
|
"--print-out-paths",
|
||||||
"--no-link",
|
"--no-link",
|
||||||
)
|
)
|
||||||
output, err := cmd.Output()
|
var stdout, stderr bytes.Buffer
|
||||||
|
cmd.Stdout = &stdout
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
|
||||||
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("failed to run nix build: %v, %s", err, stderr.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
path := strings.TrimSpace(string(output))
|
path := strings.TrimSpace(stdout.String())
|
||||||
|
|
||||||
data, err := os.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue