Skip to content

Commit

Permalink
Merge pull request #19 from jolin-io/better-error-handling
Browse files Browse the repository at this point in the history
Better error handling
  • Loading branch information
schlichtanders authored Jul 1, 2022
2 parents bd800bf + baa0b72 commit 6d88604
Show file tree
Hide file tree
Showing 23 changed files with 813 additions and 201 deletions.
41 changes: 36 additions & 5 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,44 @@ name: CompatHelper
on:
schedule:
- cron: 0 0 * * *
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
build:
CompatHelper:
runs-on: ubuntu-latest
steps:
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main()
run: julia -e 'using CompatHelper; CompatHelper.main()'
- name: Check if Julia is already available in the PATH
id: julia_in_path
run: which julia
continue-on-error: true
- name: Install Julia, but only if it is not already available in the PATH
uses: julia-actions/setup-julia@v1
with:
version: '1'
# arch: ${{ runner.arch }}
if: steps.julia_in_path.outcome != 'success'
- name: "Add the General registry via Git"
run: |
import Pkg
ENV["JULIA_PKG_SERVER"] = ""
Pkg.Registry.add("General")
shell: julia --color=yes {0}
- name: "Install CompatHelper"
run: |
import Pkg
name = "CompatHelper"
uuid = "aa819f21-2bde-4658-8897-bab36330d9b7"
version = "3"
Pkg.add(; name, uuid, version)
shell: julia --color=yes {0}
- name: "Run CompatHelper"
run: |
import CompatHelper
CompatHelper.main()
shell: julia --color=yes {0}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}
# COMPATHELPER_PRIV: ${{ secrets.COMPATHELPER_PRIV }}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.1.1] - 2022-07-01
### Added
- in case of a MethodError, a `WhereTraitsMethodError` is thrown instead which adds
detailed information about the available traits.
- `UndefVarError` is thrown if variables are used within the traits definition which are
obvious typos.
- added documentation fo WhereTraitsMethodError

## [1.1.0] - 2022-04-09

### Added
Expand Down
15 changes: 2 additions & 13 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "WhereTraits"
uuid = "c9d4e05b-6318-49cb-9b56-e0e2b0ceadd8"
authors = ["Sahm Stephan <[email protected]>"]
version = "1.1.0"
version = "1.1.1"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand All @@ -17,29 +17,18 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
SimpleMatch = "a3ae8450-d22f-11e9-3fe0-77240e25996f"
StructEquality = "6ec83bb0-ed9f-11e9-3b4c-2b04cb4e219c"
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"

[compat]
Compat = "2.1, 3"
DataTypesBasic = "1.0, 2"
ExprParsers = "1.2"
Graphs = "1.6"
IterTools = "1"
MetaGraphs = "0.7"
Pipe = "1.3"
ProxyInterfaces = "1.0"
MetaGraphs = "0.7"
Reexport = "1.2"
Setfield = "0.7, 0.8"
SimpleMatch = "1.0"
StructEquality = "2.0"
Suppressor = "0.2"
julia = "1.6"

[extras]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
StringDistances = "88034a9c-02f8-509d-84a9-84ec65e18404"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Documenter", "Test", "StringDistances", "InteractiveUtils"]
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,24 +121,17 @@ julia> conflict([1,2,3,4])
For more details, take a look at the [documentation](https://jolin-io.github.io/WhereTraits.jl/dev).


## Limitations & Future Plans
## Limitations

### Optimal Code
*Warning: While the dispatch works for dynamic functions, it will only be able to create optimal code if your traits function supports proper type-inference. E.g. you can use `Base.isempty`, however type-inference cannot see whether it will return true or false by static inspection. Hence it will use slower dynamic code.*

### MethodError
Currently if you made a mistake in your traits definition, you get a pretty incomprehensible error. What you see is merely an implementation detail and it is on the roadmap to give a nice user-friendly error-handling instead.

### Keyword arguments
Keyword arguments are at the moment not support for WhereTraits dispatch. They are just passed through.

It is planned to support Keyword arguments in some future release.

### Symbol Level

The extended where syntax is currently implemented on **symbol level**, which is why traits functions like `Base.IteratorSize` and the non-qualified `IteratorSize` (assuming you imported `import Base:IteratorSize`) are treated as two different functions, despite being the same. So for now try to only use the one style or the other.

There are plans to evaluate the symbols to functions beforehand. Still in evaluation phase.
The extended where syntax is currently implemented on **symbol level**, which is why traits functions like `Base.IteratorSize` and the non-qualified `IteratorSize` (assuming you imported `import Base: IteratorSize`) are treated as two different functions, despite being the same. So for now try to only use the one style or the other.

### Top Level Only
Currently **only top-level functions** are supported, as the syntax stores and needs information about previous function definitions, which it stores globally. If macros would get informed about whether they are defined within another function, WhereTraits could also support innerfunctions.
Expand All @@ -149,4 +142,11 @@ The `@traits` macro currently does not work well within the `Test.@testset` macr
Nevertheless there is a workaround. WhereTraits.jl exports a `@traits_test` macro variant which works better, but still might have cases where it fails. This needs to be investigated further, and maybe needs a change on `Test.@testset`.


## Other traits packages

There are many different attempts to add traits to Julia.
Everyone puts a different emphasis on different aspects of traits interfaces.

- SimpleTraits.jl
- BinaryTraits.jl
- CanonicalTraits.jl
2 changes: 1 addition & 1 deletion docs/jupyter/traits-in-julia.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@
"",
"Stacktrace:",
" [1] error(::String) at ./error.jl:33",
" [2] move3(::WhereTraits.InternalState.TraitsDefSingleton, ::Type{Tuple{WhereTraits.Syntax.Parsing._BetweenCurliesAndArgs,Animal}}, ::Whale, ::WhereTraits.Syntax.Rendering._BetweenArgsAndTypeVars, ::Type{T} where T, ::WhereTraits.Syntax.Rendering._BetweenTypeVarsAndTraits, ::Val{true}, ::Val{false}) at ./In[46]:2",
" [2] move3(::WhereTraits.InternalState.TraitsDefSingleton, ::Type{Tuple{WhereTraits.Syntax.Parsing._BetweenCurliesAndArgs,Animal}}, ::Whale, ::WhereTraits.InternalState.ArgsHelpers_BetweenArgsAndTypeVars, ::Type{T} where T, ::WhereTraits.InternalState.ArgsHelpers_BetweenTypeVarsAndTraits, ::Val{true}, ::Val{false}) at ./In[46]:2",
" [3] move3(::Whale; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at ./In[15]:2",
" [4] move3(::Whale) at ./In[15]:2",
" [5] top-level scope at In[48]:3",
Expand Down
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ makedocs(;
"WhereTraits Usage`" => "usage.md",
"WhereTraits Details`" => "details.md",
"WhereTraits.BasicTraits" => "basictraits.md",
"Combination with `isdef`" => "isdef.md",
# "Combination with `isdef`" => "isdef.md",
],
"Library" => "library.md",
],
Expand Down
Loading

2 comments on commit 6d88604

@schlichtanders
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/63464

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.1 -m "<description of version>" 6d886044ec251ad3e74577b24aade5a839579c6b
git push origin v1.1.1

Please sign in to comment.