# Is changing an error message in a package a breaking change?

**URL:** <https://discourse.julialang.org/t/is-changing-an-error-message-in-a-package-a-breaking-change/37499>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 13, 2020, 10:41am UTC](https://discourse.julialang.org/t/is-changing-an-error-message-in-a-package-a-breaking-change/37499 "2020-04-13T10:41:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [April 13, 2020, 10:41am UTC](https://discourse.julialang.org/t/is-changing-an-error-message-in-a-package-a-breaking-change/37499/1 "2020-04-13T10:41:34Z")

</div>

Let’s say that I have a module

```julia
julia> module a
       f(x::Int) = x >= 0 ? √x : error("negative")
       end
Main.a

```

that I subsequently release as a package. Now an user writes a code that specifically relies on the error message string being what it is, eg:

```julia
julia> testfn(n) = try
           Main.a.f(n)
       catch e
           buf = IOBuffer()
           showerror(buf, e)
           message = String(take!(buf))
       end
testfn (generic function with 1 method)

julia> @assert testfn(-3) == "negative"

```

In this case changing the error message in the package becomes a breaking change, even though the code throws an `ErrorException` in either case. Is this a case that package maintainers need to consider, and should this change be included in a major release (or a minor release in pre-1.0)?

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [April 13, 2020, 10:53am UTC](https://discourse.julialang.org/t/is-changing-an-error-message-in-a-package-a-breaking-change/37499/2 "2020-04-13T10:53:31Z")

</div>

I don’t know what exactly constitutes a ‘breaking change’ in the Julia ecosystem, but relying on error message content is terrible programming practice. This would mean, for example, that fixing typos would be a breaking change.

Virtually _any_ change is _conceivably_ breaking, even pure performance improvements.

(Appropriate xkcd link: [xkcd: Workflow](https://xkcd.com/1172/))

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [April 13, 2020, 12:57pm UTC](https://discourse.julialang.org/t/is-changing-an-error-message-in-a-package-a-breaking-change/37499/3 "2020-04-13T12:57:20Z")

</div>

My view would be “no”. Since there is only 1 error that could be generated people _probably_ didn’t check it’s value, just that an error was thrown. That doesn’t mean someone didn’t in which case yes this would break their code, but I think that would be rare enough to not worry about it.

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [April 13, 2020, 2:13pm UTC](https://discourse.julialang.org/t/is-changing-an-error-message-in-a-package-a-breaking-change/37499/4 "2020-04-13T14:13:18Z")

</div>

In general I recommend looking to TensorFlows documentation on what [they consider to be a breaking change](https://www.tensorflow.org/guide/versions)

In particular they **exclude** :

- Changing the **type of exception thrown** , unless the docs specified that that function threw that type of exception.\*\* (which is even stronger than changing the message. They are allowed to change the type).
- Changing something **from throwing a exception to returning the correct result** , _even if_ it was documented that it would throw an exception. (so functionality is allowed to be added)
- Return value of floating point operations. You can rely only on accuracy saying the same, not exact value.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 13, 2020, 4:22pm UTC](https://discourse.julialang.org/t/is-changing-an-error-message-in-a-package-a-breaking-change/37499/5 "2020-04-13T16:22:34Z")

</div>

> [@jishnub](#):
>
> user writes a code that specifically relies on the error message string being what it is

They should not do this. Error messages are meant to be read by people, you may change the formatting any time.

If you want to expose an API for errors, use one of the existing error types (here, `DomainError`) or introduce your own if necessary. See

[https://docs.julialang.org/en/v1/manual/control-flow/#Exception-Handling-1](https://docs.julialang.org/en/v1/manual/control-flow/#Exception-Handling-1)

for an example.

Changing the _types_ of these errors could be considered a breaking change.

---

<div class="post-metadata">

**Author:** ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)\
**Post date:** [April 13, 2020, 7:40pm UTC](https://discourse.julialang.org/t/is-changing-an-error-message-in-a-package-a-breaking-change/37499/6 "2020-04-13T19:40:46Z")

</div>

Julia packages should use [semver](https://semver.org/). Semver specifies that software using semver **must** declare a public API (point 1). So the not very useful answer to your question is that changing the error message is a breaking change if the contents of the error message are part of your declared public API.

Separately, I would argue along with most in the thread that the contents of an error message should generally not be part of your public API.
