Skip to content

Commit

Permalink
Better error report. Print all errors to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
icy committed Jul 29, 2020
1 parent b86c67c commit 259becc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ PHONY: build
build:
go build

.PHONY: clean
clean:
@rm -fv tests/*.tmp

.PHONY: tests
tests:
tests: clean
./tests/test.sh

.PHONY: all
Expand Down
5 changes: 4 additions & 1 deletion sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func repl_func(in []byte) []byte {
var_set := false
allVarSet = allVarSet && var_set
var_val := fmt.Sprintf("<%s::error::invalid_input_length>", in_st)
fmt.Fprintf(os.Stderr, "%s\n", var_val)
return []byte(var_val)
}

Expand All @@ -46,13 +47,15 @@ func repl_func(in []byte) []byte {
var_set := false
allVarSet = allVarSet && var_set
var_val := fmt.Sprintf("<%s::error::invalid_input_data>", in_st)
fmt.Fprintf(os.Stderr, "%s\n", var_val)
return []byte(var_val)
}

var_name := in_st[2 : len(in_st)-1]
var_val, var_set := os.LookupEnv(var_name)
if !var_set {
var_val = fmt.Sprintf("<%s::error::variable_unset>", var_name)
fmt.Fprintf(os.Stderr, "%s\n", var_val)
}
allVarSet = allVarSet && var_set
lastProcessedVar = var_name
Expand Down Expand Up @@ -95,7 +98,7 @@ func doLine(line string) {
} else {
fmt.Printf("%s", replLine(line))
if setMinusU && !allVarSet {
fmt.Fprintf(os.Stderr, ":: Environment variable '%s' is not set.\n", lastProcessedVar)
fmt.Fprintf(os.Stderr, ":: Some environment variable is not set. The last processed variable is '%s'.\n", lastProcessedVar)
os.Exit(1)
}
}
Expand Down

0 comments on commit 259becc

Please sign in to comment.