Dialyzer error
jarrodmoldrich opened this issue · comments
Hi Kip,
As always, thanks for your work.
Found I was getting the cryptic dialyzer error for "No local return" in one of my functions. By divide and conquer I found the offending line:
browser_image = Image.stream!(image, strip_metadata: true, suffix: ".webp", buffer_size: 5_242_880)
I had a look at the typing information of the keyword list of image_write_options
, and I noticed buffer-size
was missing and that also the image_write_options
union type included options that themselves were wrapped in a keyword list. If I'm reading it correctly – which I might not be – something like this would satisfy the typing:
browser_image = Image.stream!(image, [[strip_metadata: true], suffix: ".webp"])
... which is probably not what you intended. If I change the typing to add :buffer_size
and unwrap the keyword options as below, the dialyzer error goes away. Is this maybe how the typing is supposed to be?
@type image_write_options :: [
{:buffer_size, integer()}
| {:suffix, String.t()}
| jpeg_write_option()
| png_write_option()
| tiff_write_option()
| webp_write_option()
]
@type jpeg_write_option :: {:quality, 1..100}
| {:strip_metadata, boolean()}
| {:icc_profile, Path.t()}
| {:background, Image.pixel()}
@type jpeg_write_options :: [ jpeg_write_option() ]
@type png_write_option :: {:quality, 1..100}
| {:strip_metadata, boolean()}
| {:icc_profile, Path.t()}
| {:background, Image.pixel()}
@type png_write_options :: [ png_write_option() ]
@type tiff_write_option :: {:quality, 1..100}
| {:icc_profile, Path.t()}
| {:background, Image.pixel()}
@type tiff_write_options :: [ tiff_write_option() ]
@type heif_write_option :: {:quality, 1..100}
| {:background, Image.pixel()}
| {:compression, compression()}
@type heif_write_options :: [ heif_write_option() ]
@type webp_write_option :: {:quality, 1..100}
| {:icc_profile, Path.t()}
| {:background, Image.pixel()}
| {:strip_metadata, boolean()}
@type webp_write_options :: [ webp_write_option() ]
@jarrodmoldrich thanks for the report. Your are completely correct. I've been working on improving options and so the timing of your report is also very helpful. I've pushed ec3b08a which I think fixes this issue.
Would you consider trying it from GitHub directly and let me know? When you give the all-clear I will publish version 0.23.0.
The changelog entry now reads:
Bug Fixes
- Fix specs for
Image.Options.Write
. Thanks to @jarrodmoldrich. Closes #36.
Enhancements
-
Image.Options.Write.validate_options/2
now validates options appropriate to each image type in order to make validation more robust. -
Adds
:minimize_file_size
option toImage.write/2
for JPEG and PNG files which iftrue
will apply a range of techniques to minimize the size of the image file at the expense of time to save the image and potentially image quality.
@kipcole9 Thanks for the prompt fix! I have confirmed that latest main
works.