gofr-dev/gofr · error

failed to generate signed URL for %q: %w

Error message

failed to generate signed URL for %q: %w

What it means

GenerateSignedURL in CommonFileSystem wraps any error returned by the underlying provider's SignedURL implementation with this message, preserving the original error via %w. It means the provider did implement SignedURLProvider, but the pre-signed URL generation itself failed (e.g. bad credentials, invalid object name, or provider-side rejection). Use errors.Is/As on the wrapped cause to identify the root reason.

Source

Thrown at pkg/gofr/datasource/file/common_fs.go:713

// Returns ErrSignedURLsNotSupported if the underlying provider does not implement SignedURLProvider.
func (c *CommonFileSystem) GenerateSignedURL(ctx context.Context, name string, expiry time.Duration, opts *FileOptions) (string, error) {
	var msg string

	st := StatusError

	startTime := time.Now()
	defer c.Observe(OpSignedURL, startTime, &st, &msg)

	signer, ok := c.Provider.(SignedURLProvider)
	if !ok {
		msg = fmt.Sprintf("provider %s does not support signed URLs", c.ProviderName)
		return "", fmt.Errorf("%w: %s", ErrSignedURLsNotSupported, c.ProviderName)
	}

	url, err := signer.SignedURL(ctx, name, expiry, opts)
	if err != nil {
		msg = fmt.Sprintf("failed to generate signed URL: %v", err)
		return "", fmt.Errorf("failed to generate signed URL for %q: %w", name, err)
	}

	st = StatusSuccess
	msg = fmt.Sprintf("Generated signed URL for %q (expires in %v)", name, expiry)

	return url, nil
}

View on GitHub (pinned to 187eb24962)

Solutions

  1. Unwrap the error with errors.Is/errors.As (or %v in logs) to see the provider's underlying cause and fix that (credentials, object name, expiry).
  2. Verify the provider actually supports signed URLs and is correctly connected/authenticated before calling GenerateSignedURL.
  3. Check the object name exists and the FileOptions passed are valid for the provider.
  4. Confirm the provider implements SignedURLProvider; if not, expect ErrSignedURLsNotSupported instead.

Example fix

// before
url, err := fs.GenerateSignedURL(ctx, name, expiry, nil)
// after
if err != nil {
    var cause error
    if errors.As(err, &cause) { log.Printf("signed URL failed for %s: %v", name, cause) }
    if errors.Is(err, file.ErrSignedURLsNotSupported) { /* fall back to direct download */ }
}
Defensive patterns

Strategy: try-catch

Validate before calling

if _, ok := fs.(file.SignedURLProvider); !ok { return fallbackURL(name) }
if name == "" || expiry <= 0 { return fmt.Errorf("invalid name or expiry") }

Type guard

func supportsSignedURL(fs file.FileSystemProvider) (file.SignedURLProvider, bool) {
    sp, ok := fs.(file.SignedURLProvider)
    return sp, ok
}

Try / catch

url, err := fs.GenerateSignedURL(ctx, name, expiry, opts)
if err != nil {
    if errors.Is(err, file.ErrSignedURLsNotSupported) {
        return fallbackURL(name)
    }
    return fmt.Errorf("presign %q failed: %w", name, err) // inspect wrapped cause
}

Prevention

When it happens

Trigger: Calling CommonFileSystem.GenerateSignedURL(ctx, name, expiry, opts) when the provider's SignedURL(ctx, name, expiry, opts) returns a non-nil error — e.g. FTP/S3 provider rejects the object name, credentials are missing/expired, or the expiry/opts are invalid.

Common situations: Requesting signed URLs against providers whose SignedURL support is partial or unauthenticated; mistyped object names; expired cloud credentials; passing a zero or negative expiry that the provider rejects.

Related errors


AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01). Data as JSON: /api/errors/0284dca9a9bdc7bc. Report an issue: GitHub.