From 41ab2f5f4506752c8ac50e52b408569ec1b47c01 Mon Sep 17 00:00:00 2001 From: Andy Manning Date: Tue, 24 Aug 2021 14:55:52 +1200 Subject: [PATCH 1/2] Issue #28 Fix, check for tika.jar --- tika/server.go | 8 +++++++- tika/server_test.go | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tika/server.go b/tika/server.go index 37d33c7..9cc9a81 100644 --- a/tika/server.go +++ b/tika/server.go @@ -37,7 +37,6 @@ import ( // since you can pass its URL directly to a Client. // Additional Java system properties can be added to a Taka Server before // startup by adding to the JavaProps map - type Server struct { jar string url string // url is derived from port. @@ -91,6 +90,13 @@ func NewServer(jar, port string) (*Server, error) { if jar == "" { return nil, fmt.Errorf("no jar file specified") } + + //Check if the jar file exists + _, err := os.Stat(jar) + if os.IsNotExist(err) { + return nil, fmt.Errorf("jar file [%s] does not exist", jar) + } + if port == "" { port = "9998" } diff --git a/tika/server_test.go b/tika/server_test.go index 6e67ae6..e269e8a 100644 --- a/tika/server_test.go +++ b/tika/server_test.go @@ -46,7 +46,8 @@ func TestNewServerError(t *testing.T) { port string }{ {name: "no jar path"}, - {name: "invalid port", jar: "jar/path", port: "%31"}, + {name: "invalid port", jar: "test_resources/test.jar", port: "%31"}, + {name: "missing jar file", jar: "test_resources/missing.jar"}, } for _, test := range tests { if _, err := NewServer(test.jar, test.port); err == nil { From a49455b51be8fde3f0bd0bcd07878823c6edc12b Mon Sep 17 00:00:00 2001 From: Andy Manning Date: Tue, 1 Feb 2022 10:08:08 +1300 Subject: [PATCH 2/2] Updated after PR comments --- tika/server.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tika/server.go b/tika/server.go index 9cc9a81..758d77c 100644 --- a/tika/server.go +++ b/tika/server.go @@ -91,10 +91,9 @@ func NewServer(jar, port string) (*Server, error) { return nil, fmt.Errorf("no jar file specified") } - //Check if the jar file exists - _, err := os.Stat(jar) - if os.IsNotExist(err) { - return nil, fmt.Errorf("jar file [%s] does not exist", jar) + // Check if the jar file exists. + if _, err := os.Stat(jar); os.IsNotExist(err) { + return nil, fmt.Errorf("jar file %q does not exist", jar) } if port == "" {