Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing jar file fails silently #17

Closed
bitcoin-coder-bob opened this issue Mar 25, 2020 · 0 comments
Closed

Missing jar file fails silently #17

bitcoin-coder-bob opened this issue Mar 25, 2020 · 0 comments

Comments

@bitcoin-coder-bob
Copy link
Contributor

When calling NewServer if the jar file is not found (bad path or just does not exist), NewServer does not return an error. When the Start function is then called, it will also not return an error.

The underlying line of code being called in Start (line 77) is:
cmd := command("java", "-jar", s.jar, "-p", s.port) which is then started with:
if err := cmd.Start(); err != nil { return err } which has no problem except for the fact that it is erring silently. If we read from standard error we can see the problem being logged, but the current code is not capturing this, since cmd.Start() did not err. Thus, this is a silent "failure". The code does not fail but the call to start the Server never actually succeeds.

Consider the following example code:

server, err = tika.NewServer("tika-server-1.19.jar", "")
	if err != nil {
		l.Error().Msgf("Error creating Tika server: %s", err.Error())
		return
	} else {
		l.Info().Msgf("SERVER: %v", server)
	}
	err = server.Start(context.Background())
	if err != nil {
		l.Error().Msgf("Error starting Tika server: %s", err.Error())
		return
	} else {
		l.Info().Msg("No issue starting server")
	}
	l.Info().Msg("HERE")

This prints: SERVER: &{tika-server-1.19.jar http://localhost:9998 9998 <nil>} and HERE is never printed since the line is never reached. The Start function never completes.

I propose the following fix to be placed in the first line of the Start function:

if _, err := os.Stat(s.jar); os.IsNotExist(err) {
		return err
	}

This will allow for immediate failure if the tika jar file was not found or does not exist.

I would like to make a PR for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants