PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.25k stars 2.69k forks source link

Verbose exceptions and error messages. #2464

Open ghost opened 1 year ago

ghost commented 1 year ago

As a developer, I'd like to be able to have a hint of where problems arise when generating or manipulating a Word document.

        $tagPos = strpos($this->tempDocumentMainPart, $search);
        if (!$tagPos) {
            throw new Exception('Can not clone row, template variable not found or variable contains markup.');
        }

We're all developers here, wouldn't it be nice to toss in the $search variable into the error message? This would also be a nice to have for parse errors of DOM/HTML as well. It just throws an error, but doesn't give you any clue where the problem might be.

Maybe if I get some time, I'll create a PR for this.

thomasb88 commented 1 year ago

tempDocumentMainPart can be a quite big xml file, which not fits "Users level" messages constraint.

My point of view is that allowing to provide an external logManager object that can provide any debug information for the tool that use PHPWord would have sense.

I just added my own while debugging the splitted Macros problem, which looks like class TemplateProcessor { ... /**

And then can be used this way $log_obj = $this->logModel; if(null !== $log_obj){ $log_obj->dumpDataToLog(, , ); }

Then a list of usefull content can be defined.

Note that i added this cause i let users create custom words files that have to be used as templates -)

ghost commented 1 year ago

That's a fantastic solution!!

thomasb88 commented 1 year ago

Tks Tim -)

Note i also had the same problem, for example when trying to debug Image Reading.

And so i added also this kind of solution using AbstractReader, AbstractPart and AbstractElement object.

I will try to make a branch soon for this kind of solution, but i'm interested in any return that could make it more efficient/easy to use.