Skip to content

Commit 0931b89

Browse files
authored
Small refinements (#1)
- Add testing to CI. - Clarify that this isn’t an officially supported product. - Clarify that this outputs ext JSON. - Refine a couple error messages.
1 parent e5205d9 commit 0931b89

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

.github/workflows/test.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
on:
2+
push:
3+
branches:
4+
- '*'
5+
tags-ignore:
6+
- '*'
7+
pull_request:
8+
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- run: uname -a
15+
- run: ldconfig -p
16+
- run: lsb_release -a
17+
18+
- name: Check out repository
19+
uses: actions/checkout@v4
20+
21+
- name: Fetch Go
22+
uses: actions/setup-go@v5
23+
24+
- name: Test
25+
run: go test -v ./... -race

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# mongodump-parser
22

3+
This Repository is **NOT** an officially supported MongoDB product.
4+
35
This simple tool reads a
46
[mongodump](https://www.mongodb.com/docs/database-tools/mongodump/) archive
57
on its standard input, parses the archive’s header & collection metadata,
6-
then writes the result as a JSON document to standard output.
8+
then writes the result as a
9+
[MongoDB Extended JSON](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/)
10+
document to standard output.
711

812
To build it, just run `go build`.

main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func main() {
3737
var cmd = cli.Command{
3838
Name: "mongodump-parser",
3939
Usage: "parse mongodump archive files",
40-
Description: wordwrap.WrapString("This tool reads a mongodump archive file from standard input, parses its header, then outputs the parse to standard output. This lets you see an archive’s contents without actually restoring it.", uint(colWidth-4)),
40+
Description: wordwrap.WrapString("This tool reads a mongodump archive file from standard input, parses its header, then outputs the parse to standard output in MongoDB Extended JSON. This lets you see an archive’s contents without actually restoring it.", uint(colWidth-4)),
4141
Action: func(_ context.Context, cmd *cli.Command) error {
4242
return run(cmd)
4343
},
@@ -71,7 +71,7 @@ func run(cmd *cli.Command) error {
7171
func getReport(input io.Reader, errOut io.Writer) (Report, error) {
7272
err := checkMagicBytes(input)
7373
if err != nil {
74-
return Report{}, err
74+
return Report{}, errors.Wrap(err, "this does not appear to be a mongodump archive")
7575
}
7676

7777
header := bson.D{}
@@ -152,7 +152,7 @@ func checkMagicBytes(input io.Reader) error {
152152

153153
magicNum := binary.LittleEndian.Uint32(magicBytes[:])
154154
if magicNum != archive.MagicNumber {
155-
return fmt.Errorf("expected magic number header (%v, %d); should be %d", magicBytes, magicNum, archive.MagicNumber)
155+
return fmt.Errorf("unexpected magic number header (%v, %d); should be %d", magicBytes, magicNum, archive.MagicNumber)
156156
}
157157

158158
return nil

0 commit comments

Comments
 (0)