Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Allow SetError to set f.err to nil #79

@cocoliliace

Description

@cocoliliace

SetError does not allow users to overwrite the existing error with nil.

fpdf/fpdf.go

Lines 291 to 295 in 504c6dd

func (f *Fpdf) SetError(err error) {
if f.err == nil && err != nil {
f.err = err
}
}

Is there a reason for this restriction? I came across a use case where I would like to retry the operation upon failure, but since the internal f.err field is not nil, calling the same operation again would just return immediately with the existing error.

For example, when I call f.RegisterImageOptionsReader, I know the image type is either jpg or png and I am passing the correct mime type most of the time. Every once in a while, I pass in an incorrect mime type (eg. a png buffer with opts.ImageType set to jpg) and get an error. When this happens, I try to solve it by calling f.RegisterImageOptionsReader again with a different mime type (jpg in this case). However, f.RegisterImageOptionsReader returns with an error immediately because there is a previous error and I cannot overwrite it with nil.

fpdf/fpdf.go

Lines 3407 to 3411 in 504c6dd

func (f *Fpdf) RegisterImageOptionsReader(imgName string, options ImageOptions, r io.Reader) (info *ImageInfoType) {
// Thanks, Ivan Daniluk, for generalizing this code to use the Reader interface.
if f.err != nil {
return
}

I can help submit a PR for this if we decide to remove this restriction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions