ingomohr / docwriter

API to write docx documents
MIT License
1 stars 0 forks source link

Improve Error Message in SimpleDocxProcess when No Document is Present #49

Open ingomohr opened 3 years ago

ingomohr commented 3 years ago

In SimpleDocxProcessor, when you work on a document and you didn't create one before, the error message just points out that there is no doc yet. It doesn't, however, point out how to create one - e.g. via method createDocument().

The task is to improve the error message to give a hint on how to create the document.

Ejaz29 commented 3 years ago

hi @ingomohr I am beginner to opensource but I would like to contribute to the issue if it is open. Can you help me?

ingomohr commented 3 years ago

Hi @Ejaz29! Thank you for getting in touch.

Are you familiar with Java projects? I could also provide you with a small how-to on how to on working on the project - if you think that could help you.

I just re-reviewed the code and I think there actually is less to do than I thought when I created this issue. Well, that could be good for you if you wanted to take the opportunity to have something small to contribute. ;)

What's the problem?

Let's say you have the following code in some Java class: This is the simplest way of using the SimpleDocxProcessor. It will create a new *.docx file containing only "Hello world!"

SimpleDocxProcessor processor = new SimpleDocxProcessor();

//  processor.createDocument();

processor.addMarkdown("Hello **world**!");

try {
    File tempFile = File.createTempFile("docwriter-eclipse-test", ".docx");
    processor.saveDocumentToPath(tempFile);
} catch (IOException e) {
  // log
}

Actually, it won't create that file - and that is because the createDocument() method is not called. A document, however, is required to exist - either by creating one or by loading one.

Executing the snippet above in a (Java class with a main method) will produce a NullPointerException with following message.

"No document found. See createDocument() and loadDocument() methods."

When I created this issue, I missed that I already had added some hint to the doc creation - the "See createDocument()...". But I would like to have both the exception type and the message changed - and here is why:

So what do do?

My suggestion is to

@Ejaz29 I you have some other suggestion or thoughts on the issue you want to share, I would appreciate that. :)

Ejaz29 commented 3 years ago

Thank you for the detailed explanation @ingomohr :) I will work on it. You can also provide me with how to work on a project that would be really helpful. Thank you.

ingomohr commented 3 years ago

https://github.com/ingomohr/docwriter/blob/master/src/test/java/org/ingomohr/docwriter/docx/TestSimpleDocxProcessor.java

@Ejaz29 Are you sure? I see a test class by that name. 😉

The goal for this issue is to update the test to the new expectation (as suggested above) and to update the code so that all tests pass again.

Generally, this is what you can do:

What knowledge do I need?

What tools do I need?

How to Build the Project and run the tests

Ejaz29 commented 3 years ago

Sorry @ingomohr I didn't notice. I am good in java but do not have even basic understanding of maven and JUnit5. So if someone else want to contribute they can. I will still be lurking around waiting for the right issue for me to contribute in your repo. :) Thank you for the detailed explanation and I am sorry to waste your time.

ingomohr commented 3 years ago

Hey @Ejaz29, thanks for the update. And you didn't waste my time, don't worry. :) Should you change your mind: I won't have time to resolve this issue myself before tomorrow evening.