Skip to content

Commit

Permalink
cmd/sunlight: print a helpful error if the inception date is wrong
Browse files Browse the repository at this point in the history
Fixes #26
  • Loading branch information
FiloSottile committed Dec 15, 2024
1 parent 49406f3 commit 737ae11
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion cmd/sunlight/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"encoding/base64"
"encoding/json"
"encoding/pem"
"errors"
"flag"
"io"
"log/slog"
Expand Down Expand Up @@ -434,7 +435,10 @@ func main() {
}

l, err := ctlog.LoadLog(ctx, cc)
if err != nil {
if errors.Is(err, ctlog.ErrLogNotFound) {
fatalError(logger, "log not found, but today is not the Inception date",
"today", time.Now().Format(time.DateOnly), "inception", lc.Inception)
} else if err != nil {
fatalError(logger, "failed to load log", "err", err)
}
defer l.CloseCache()
Expand Down
4 changes: 4 additions & 0 deletions internal/ctlog/ctlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ var optsStaging = &UploadOptions{Compress: true}
var optsIssuer = &UploadOptions{ContentType: "application/pkix-cert", Immutable: true}
var optsCheckpoint = &UploadOptions{ContentType: "text/plain; charset=utf-8"}

var ErrLogNotFound = errors.New("log not found")

// A LockBackend is a database that supports compare-and-swap operations.
//
// It is shared across multiple Log instances, and is used only to store the
Expand All @@ -401,6 +403,8 @@ var optsCheckpoint = &UploadOptions{ContentType: "text/plain; charset=utf-8"}
type LockBackend interface {
// Fetch obtains the current checkpoint for a given log, as well as the data
// necessary to perform a compare-and-swap operation.
//
// It must return ErrLogNotFound if the log doesn't exist.
Fetch(ctx context.Context, logID [sha256.Size]byte) (LockedCheckpoint, error)

// Replace uploads a new checkpoint, atomically checking that the old
Expand Down
3 changes: 1 addition & 2 deletions internal/ctlog/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ctlog
import (
"context"
"crypto/sha256"
"errors"
"fmt"
"log/slog"
"net/http"
Expand Down Expand Up @@ -91,7 +90,7 @@ func (b *DynamoDBBackend) Fetch(ctx context.Context, logID [sha256.Size]byte) (L
return nil, err
}
if resp.Item == nil {
return nil, errors.New("checkpoint not found")
return nil, ErrLogNotFound
}
return &dynamoDBCheckpoint{logID: logID,
body: resp.Item["checkpoint"].(*types.AttributeValueMemberB).Value}, nil
Expand Down

0 comments on commit 737ae11

Please sign in to comment.