Skip to content

Commit

Permalink
Improved file-not-found handling (#1508)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Feb 26, 2024
1 parent 3201f9c commit aff4b9f
Show file tree
Hide file tree
Showing 43 changed files with 85 additions and 61 deletions.
3 changes: 2 additions & 1 deletion pkg/input/record_reader_csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ func (reader *RecordReaderCSV) Read(
)
if err != nil {
errorChannel <- err
} else {
reader.processHandle(handle, "(stdin)", &context, readerChannel, errorChannel, downstreamDoneChannel)
}
reader.processHandle(handle, "(stdin)", &context, readerChannel, errorChannel, downstreamDoneChannel)
} else {
for _, filename := range filenames {
handle, err := lib.OpenFileForRead(
Expand Down
38 changes: 19 additions & 19 deletions pkg/input/record_reader_csvlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,16 @@ func (reader *RecordReaderCSVLite) Read(
)
if err != nil {
errorChannel <- err
return
} else {
reader.processHandle(
handle,
"(stdin)",
&context,
readerChannel,
errorChannel,
downstreamDoneChannel,
)
}
reader.processHandle(
handle,
"(stdin)",
&context,
readerChannel,
errorChannel,
downstreamDoneChannel,
)
} else {
for _, filename := range filenames {
handle, err := lib.OpenFileForRead(
Expand All @@ -114,17 +114,17 @@ func (reader *RecordReaderCSVLite) Read(
)
if err != nil {
errorChannel <- err
return
} else {
reader.processHandle(
handle,
filename,
&context,
readerChannel,
errorChannel,
downstreamDoneChannel,
)
handle.Close()
}
reader.processHandle(
handle,
filename,
&context,
readerChannel,
errorChannel,
downstreamDoneChannel,
)
handle.Close()
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/input/record_reader_dkvp_nidx.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ func (reader *RecordReaderDKVPNIDX) Read(
)
if err != nil {
errorChannel <- err
} else {
reader.processHandle(handle, "(stdin)", &context, readerChannel, errorChannel, downstreamDoneChannel)
}
reader.processHandle(handle, "(stdin)", &context, readerChannel, errorChannel, downstreamDoneChannel)
} else {
for _, filename := range filenames {
handle, err := lib.OpenFileForRead(
Expand Down
3 changes: 2 additions & 1 deletion pkg/input/record_reader_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ func (reader *RecordReaderJSON) Read(
)
if err != nil {
errorChannel <- err
} else {
reader.processHandle(handle, "(stdin)", &context, readerChannel, errorChannel, downstreamDoneChannel)
}
reader.processHandle(handle, "(stdin)", &context, readerChannel, errorChannel, downstreamDoneChannel)
} else {
for _, filename := range filenames {
handle, err := lib.OpenFileForRead(
Expand Down
38 changes: 19 additions & 19 deletions pkg/input/record_reader_pprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ func (reader *RecordReaderPprintBarredOrMarkdown) Read(
)
if err != nil {
errorChannel <- err
return
} else {
reader.processHandle(
handle,
"(stdin)",
&context,
readerChannel,
errorChannel,
downstreamDoneChannel,
)
}
reader.processHandle(
handle,
"(stdin)",
&context,
readerChannel,
errorChannel,
downstreamDoneChannel,
)
} else {
for _, filename := range filenames {
handle, err := lib.OpenFileForRead(
Expand All @@ -118,17 +118,17 @@ func (reader *RecordReaderPprintBarredOrMarkdown) Read(
)
if err != nil {
errorChannel <- err
return
} else {
reader.processHandle(
handle,
filename,
&context,
readerChannel,
errorChannel,
downstreamDoneChannel,
)
handle.Close()
}
reader.processHandle(
handle,
filename,
&context,
readerChannel,
errorChannel,
downstreamDoneChannel,
)
handle.Close()
}
}
}
Expand Down
38 changes: 19 additions & 19 deletions pkg/input/record_reader_tsv.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ func (reader *RecordReaderTSV) Read(
)
if err != nil {
errorChannel <- err
return
} else {
reader.processHandle(
handle,
"(stdin)",
&context,
readerChannel,
errorChannel,
downstreamDoneChannel,
)
}
reader.processHandle(
handle,
"(stdin)",
&context,
readerChannel,
errorChannel,
downstreamDoneChannel,
)
} else {
for _, filename := range filenames {
handle, err := lib.OpenFileForRead(
Expand All @@ -96,17 +96,17 @@ func (reader *RecordReaderTSV) Read(
)
if err != nil {
errorChannel <- err
return
} else {
reader.processHandle(
handle,
filename,
&context,
readerChannel,
errorChannel,
downstreamDoneChannel,
)
handle.Close()
}
reader.processHandle(
handle,
filename,
&context,
readerChannel,
errorChannel,
downstreamDoneChannel,
)
handle.Close()
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/input/record_reader_xtab.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ func (reader *RecordReaderXTAB) Read(
)
if err != nil {
errorChannel <- err
} else {
reader.processHandle(handle, "(stdin)", &context, readerChannel, errorChannel, downstreamDoneChannel)
}
reader.processHandle(handle, "(stdin)", &context, readerChannel, errorChannel, downstreamDoneChannel)
} else {
for _, filename := range filenames {
handle, err := lib.OpenFileForRead(
Expand Down
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/csv/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --csv cat /nonesuch/nope/never
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/csv/experr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr: open /nonesuch/nope/never: no such file or directory.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/dkvp/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --dkvp cat /nonesuch/nope/never
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/dkvp/experr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr: open /nonesuch/nope/never: no such file or directory.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/imd/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --imd cat /nonesuch/nope/never
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/imd/experr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr: open /nonesuch/nope/never: no such file or directory.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/json/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --json cat /nonesuch/nope/never
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/json/experr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr: open /nonesuch/nope/never: no such file or directory.
2 changes: 2 additions & 0 deletions test/cases/non-windows/file-not-found/json/expout
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[
]
Empty file.
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/jsonl/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --jsonl cat /nonesuch/nope/never
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/jsonl/experr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr: open /nonesuch/nope/never: no such file or directory.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/nidx/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --nidx cat /nonesuch/nope/never
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/nidx/experr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr: open /nonesuch/nope/never: no such file or directory.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/pprint/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --pprint cat /nonesuch/nope/never
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/pprint/experr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr: open /nonesuch/nope/never: no such file or directory.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/tsv/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --tsv cat /nonesuch/nope/never
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/tsv/experr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr: open /nonesuch/nope/never: no such file or directory.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/xtab/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --xtab cat /nonesuch/nope/never
1 change: 1 addition & 0 deletions test/cases/non-windows/file-not-found/xtab/experr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr: open /nonesuch/nope/never: no such file or directory.
Empty file.
Empty file.

0 comments on commit aff4b9f

Please sign in to comment.