TylerBrock / saw

Fast, multi-purpose tool for AWS CloudWatch Logs
MIT License
1.4k stars 77 forks source link

Bug: Exception raised when LogStream has no events. #53

Closed treacher closed 2 years ago

treacher commented 4 years ago

When running saw with an empty LogStream I get the following exception:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x13d890d]

goroutine 1 [running]:
github.com/TylerBrock/saw/config.(*Configuration).TopStreamNames.func1(0x1, 0x0, 0x0)
    /Users/treacher/dev/personal/saw/config/configuration.go:116 +0x18d
sort.doPivot_func(0xc00051fb98, 0xc0004ae5e0, 0x0, 0x31, 0x18, 0xc0004ae5c0)
    /usr/local/Cellar/go/1.14/libexec/src/sort/zfuncversion.go:83 +0x48b
sort.quickSort_func(0xc00051fb98, 0xc0004ae5e0, 0x0, 0x31, 0xc)
    /usr/local/Cellar/go/1.14/libexec/src/sort/zfuncversion.go:143 +0x9a
sort.Slice(0x14a4d60, 0xc0004ae5c0, 0xc00051fb98)
    /usr/local/Cellar/go/1.14/libexec/src/sort/slice.go:17 +0xf1
github.com/TylerBrock/saw/config.(*Configuration).TopStreamNames(0x198dce0, 0xc000252830, 0xc00013d580, 0x100ac5c)
    /Users/treacher/dev/personal/saw/config/configuration.go:112 +0x8d
github.com/TylerBrock/saw/config.(*Configuration).FilterLogEventsInput(0x198dce0, 0xc00013d580)
    /Users/treacher/dev/personal/saw/config/configuration.go:82 +0x3da
github.com/TylerBrock/saw/blade.(*Blade).GetEvents(0xc000120d20)
    /Users/treacher/dev/personal/saw/blade/blade.go:95 +0x62
github.com/TylerBrock/saw/cmd.glob..func2(0x1987c00, 0xc00012e3c0, 0x1, 0x5)
    /Users/treacher/dev/personal/saw/cmd/get.go:38 +0xaa
github.com/spf13/cobra.(*Command).execute(0x1987c00, 0xc00012e370, 0x5, 0x5, 0x1987c00, 0xc00012e370)
    /Users/treacher/go/pkg/mod/github.com/spf13/cobra@v0.0.3/command.go:766 +0x29d
github.com/spf13/cobra.(*Command).ExecuteC(0x19880c0, 0x0, 0x43000, 0xc000074058)
    /Users/treacher/go/pkg/mod/github.com/spf13/cobra@v0.0.3/command.go:852 +0x2ea
github.com/spf13/cobra.(*Command).Execute(...)
    /Users/treacher/go/pkg/mod/github.com/spf13/cobra@v0.0.3/command.go:800
main.main()
    /Users/treacher/dev/personal/saw/saw.go:10 +0x2d

I've pinpointed this error to be coming from this line on code: https://github.com/TylerBrock/saw/blob/master/config/configuration.go#L112

When the stream has no events it doesn't have a LastEventTimestamp field. See the below print out of the object comparison that causes the exception:

First: {
  Arn: "REDACTED",
  CreationTime: 1592286543348,
  LogStreamName: "REDACTED",
  StoredBytes: 0
}

Second: {
  Arn: "REDACTED",
  CreationTime: 1590782568670,
  FirstEventTimestamp: 1590782569669,
  LastEventTimestamp: 1590782570342,
  LastIngestionTime: 1590782573697,
  LogStreamName: "REDACTED",
  StoredBytes: 0,
  UploadSequenceToken: "REDACTED"
}