From e4caf9278ec2b6711b59efbb80fe9551f35d02b3 Mon Sep 17 00:00:00 2001 From: Paul Fleischer Date: Wed, 16 Mar 2022 14:08:46 +0100 Subject: [PATCH] Make write_to and write_to_memory adhere to their typespecs The typespecs state that {:ok, String.t()} is returned, but :zip.create will return {:ok, [char()]}. --- lib/elixlsx.ex | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/elixlsx.ex b/lib/elixlsx.ex index b5a0ec4..582f5d9 100644 --- a/lib/elixlsx.ex +++ b/lib/elixlsx.ex @@ -46,7 +46,10 @@ defmodule Elixlsx do @spec write_to(Elixlsx.Workbook.t(), String.t()) :: {:ok, String.t()} | {:error, any()} def write_to(workbook, filename) do wci = Elixlsx.Compiler.make_workbook_comp_info(workbook) - :zip.create(to_charlist(filename), Elixlsx.Writer.create_files(workbook, wci)) + case :zip.create(to_charlist(filename), Elixlsx.Writer.create_files(workbook, wci)) do + {:ok, _} -> {:ok, filename} + {:error, error} -> {:error, error} + end end @doc ~S""" @@ -58,6 +61,9 @@ defmodule Elixlsx do {:ok, {charlist, binary}} | {:error, any()} def write_to_memory(workbook, filename) do wci = Elixlsx.Compiler.make_workbook_comp_info(workbook) - :zip.create(to_charlist(filename), Elixlsx.Writer.create_files(workbook, wci), [:memory]) + case :zip.create(to_charlist(filename), Elixlsx.Writer.create_files(workbook, wci), [:memory]) do + {:ok, _} -> {:ok, filename} + {:error, error} -> {:error, error} + end end end