I’ve tried .. using both PrintWrite and Buffered Reader to print the output and it is working fine in my local.
Here are my logs in local:
curl -v http://localhost:4221/mango
* Host localhost:4221 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
* Trying [::1]:4221...
* Connected to localhost (::1) port 4221
> GET /mango HTTP/1.1
> Host: localhost:4221
> User-Agent: curl/8.7.1
> Accept: */*
>
* Request completely sent off
< HTTP/1.1 404 Not Found
<
* no chunk, no close, no size. Assume close to signal end
* Closing connection
And here’s a snippet of my code:
System.out.println("Logs from your program will appear here!");
// Uncomment this block to pass the first stage
try {
ServerSocket serverSocket = new ServerSocket(4221);
// Since the tester restarts your program quite often, setting SO_REUSEADDR
// ensures that we don't run into 'Address already in use' errors
serverSocket.setReuseAddress(true);
// Wait for connection from client.
// serverSocket.accept();
var clientSocket = serverSocket.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
// BufferedWriter out = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
String requestLine = in.readLine();
String[] requestParts = requestLine.split(" ");
String pathParams = requestParts[1];
String httpResponse;
if (pathParams.equals("/") || pathParams.isBlank()) {
httpResponse = "HTTP/1.1 200 OK\r\n\r\n";
} else {
httpResponse = "HTTP/1.1 404 Not Found\r\n\r\n";
}
out.println(httpResponse);
// out.flush();
clientSocket.close();
System.out.println("Response Message has been sent back to the client");
} catch (IOException e) {
System.out.println("IOException: " + e.getMessage());
}
It is showing Tests Failed and it is unable to pick the new code in the codecrafters UI.
[tester::#IH0] Running tests for Stage #IH0 (Extract URL path)
[tester::#IH0] $ ./your_program.sh
[your_program] Logs from your program will appear here!
[tester::#IH0] $ curl -v http://localhost:4221/mango
[your_program] Modified message has been sent to the client
[tester::#IH0] Expected status code 404, got 200
[tester::#IH0] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)
Hello @andy1li It is not working. Looks like it is not even picking up the new code. It is showing tests failed in the UI with following logs. The log statement at the end has been updated from past few commits. I even modified the debug to be true in the yml file but even that is not working. Following are the failure logs:
[compile] [INFO]
[compile] [INFO] --------------< io.codecrafters:codecrafters-http-server >--------------
[compile] [INFO] Building codecrafters-http-server 1.0
[compile] [INFO] from pom.xml
[compile] [INFO] --------------------------------[ jar ]---------------------------------
[compile] [INFO]
[compile] [INFO] --- resources:3.3.1:resources (default-resources) @ codecrafters-http-server ---
[compile] [INFO] skip non existing resourceDirectory /app/src/main/resources
[compile] [INFO]
[compile] [INFO] --- compiler:3.13.0:compile (default-compile) @ codecrafters-http-server ---
[compile] [INFO] Recompiling the module because of changed source code.
[compile] [INFO] Compiling 1 source file with javac [debug target 23] to target/classes
[compile] [INFO]
[compile] [INFO] --- resources:3.3.1:testResources (default-testResources) @ codecrafters-http-server ---
[compile] [INFO] skip non existing resourceDirectory /app/src/test/resources
[compile] [INFO]
[compile] [INFO] --- compiler:3.13.0:testCompile (default-testCompile) @ codecrafters-http-server ---
[compile] [INFO] No sources to compile
[compile] [INFO]
[compile] [INFO] --- surefire:3.2.5:test (default-test) @ codecrafters-http-server ---
[compile] [INFO] No tests to run.
[compile] [INFO]
[compile] [INFO] --- jar:3.4.1:jar (default-jar) @ codecrafters-http-server ---
[compile] [INFO] Building jar: /app/target/codecrafters-http-server-1.0.jar
[compile] [INFO]
[compile] [INFO] --- assembly:3.7.1:single (make-assembly) @ codecrafters-http-server ---
[compile] [INFO] Building jar: /tmp/codecrafters-build-http-server-java/codecrafters-http-server.jar
[compile] [WARNING] Configuration option 'appendAssemblyId' is set to false.
[compile] Instead of attaching the assembly file: /tmp/codecrafters-build-http-server-java/codecrafters-http-server.jar, it will become the file for main project artifact.
[compile] NOTE: If multiple descriptors or descriptor-formats are provided for this project, the value of this file will be non-deterministic!
[compile] [WARNING] Replacing pre-existing project main-artifact file: /app/target/codecrafters-http-server-1.0.jar
[compile] with assembly file: /tmp/codecrafters-build-http-server-java/codecrafters-http-server.jar
[compile] [INFO] ------------------------------------------------------------------------
[compile] [INFO] BUILD SUCCESS
[compile] [INFO] ------------------------------------------------------------------------
[compile] [INFO] Total time: 2.739 s
[compile] [INFO] Finished at: 2025-05-16T18:10:49Z
[compile] [INFO] ------------------------------------------------------------------------
[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.
[tester::#IH0] Running tests for Stage #IH0 (Extract URL path)
[tester::#IH0] $ ./your_program.sh
[your_program] Logs from your program will appear here!
[tester::#IH0] $ curl -v http://localhost:4221/mango
[your_program] Modified message has been sent to the client
[tester::#IH0] Expected status code 404, got 200
[tester::#IH0] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)```
@andy1li
But I can still work on other challenges, right? My tests will show a failure in the UI. I should still be able to test them by running the server in local and hit the API.
Please correct me if my understanding is wrong.
Sorry for the confusion. The error you’re seeing is from a previous submission (about 20 hours ago). Your recent pushes didn’t trigger a new submission since the current stage requires a membership.
@andy1li
It is still unclear. I should be able to explore challenges that are not free and run them in my local, right? It will not show as passed in the UI, but I will be able to go through them and learn from them.
I hope my question is clear. Please let me know if you need any further clarifications.
I should be able to explore challenges that are not free and run them in my local, right? It will not show as passed in the UI, but I will be able to go through them and learn from them.
Yes, you can absolutely continue building locally.
Just note that without a membership, you won’t be able to run tests on our servers for the member-only stages.