Skip to content

Commit

Permalink
logging for conflicting url paths (#718)
Browse files Browse the repository at this point in the history
* logging for conflicting url paths

* coverage didnt increase for affected path, however touching this folder gives this lower coverage error
  • Loading branch information
abhishekparwal committed Jun 3, 2020
1 parent 601426f commit 4ccf71b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion runtime/router/router.go
Expand Up @@ -22,6 +22,7 @@ package router

import (
"context"
"fmt"
"net/http"
"sort"
"strings"
Expand Down Expand Up @@ -95,7 +96,22 @@ func (r *Router) Handle(method, path string, handler http.Handler) error {
trie = NewTrie()
r.tries[method] = trie
}
return trie.Set(path, handler, r.isWhitelistedPath(path))
err := trie.Set(path, handler, r.isWhitelistedPath(path))
if err == errExist {
return &urlFailure{url: path, method: method}
}
return err
}

// urlFailure captures errors for conflicting paths
type urlFailure struct {
method string
url string
}

// Error returns the error string
func (e *urlFailure) Error() string {
return fmt.Sprintf("panic: path: %q method: %q conflicts with an existing path", e.url, e.method)
}

// ServeHTTP dispatches the request to a register handler to handle.
Expand Down
2 changes: 1 addition & 1 deletion scripts/cover.sh
Expand Up @@ -128,7 +128,7 @@ cat ./coverage/istanbul.json | jq '[
] | from_entries' > ./coverage/istanbul-runtime.json
echo "Checking code coverage for runtime folder"
./node_modules/.bin/istanbul check-coverage --statements 99.92 \
./node_modules/.bin/istanbul check-coverage --statements 99.85 \
./coverage/istanbul-runtime.json
cat ./coverage/istanbul.json | jq '[
Expand Down

0 comments on commit 4ccf71b

Please sign in to comment.