Skip to content

Commit

Permalink
Clean use of System.err
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoet-jh committed Dec 19, 2024
1 parent 5a55056 commit 085a740
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

Expand All @@ -34,6 +36,8 @@
@Component
public class NihmsHarvesterCLIRunner implements CommandLineRunner {

private static final Logger LOG = LoggerFactory.getLogger(NihmsHarvesterCLIRunner.class);

/**
* Request for help/usage documentation
*/
Expand Down Expand Up @@ -96,7 +100,6 @@ public void run(String... args) {
/* Handle general options such as help, version */
if (this.help) {
parser.printUsage(System.err);
System.err.println();
System.exit(0);
}

Expand All @@ -121,16 +124,10 @@ public void run(String... args) {
nihmsHarvester.harvest(statusesToProcess, harvestPeriodMonths);

} catch (CmdLineException e) {
/**
* This is an error in command line args, just print out usage data
* and description of the error.
*/
System.err.println(e.getMessage());
parser.printUsage(System.err);
System.exit(1);
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getMessage());
LOG.error("Error running Nihms Harvester", e);
System.exit(1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

Expand All @@ -30,6 +32,9 @@
*/
@Component
public class NihmsTransformLoadCLIRunner implements CommandLineRunner {

private static final Logger LOG = LoggerFactory.getLogger(NihmsTransformLoadCLIRunner.class);

/**
* Request for help/usage documentation
*/
Expand Down Expand Up @@ -77,7 +82,6 @@ public void run(String... args) {
/* Handle general options such as help, version */
if (this.help) {
parser.printUsage(System.err);
System.err.println();
System.exit(0);
}

Expand All @@ -97,20 +101,11 @@ public void run(String... args) {
nihmsTransformLoadService.transformAndLoadFiles(statusesToProcess);

} catch (CmdLineException e) {
/**
* This is an error in command line args, just print out usage data
* and description of the error.
*/
System.err.println(e.getMessage());
parser.printUsage(System.err);
System.err.println();
System.exit(1);

} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getMessage());
LOG.error("Error running Nihms Transform and Load", e);
System.exit(1);

}
}
}

0 comments on commit 085a740

Please sign in to comment.