Solved

Is there a way to log an error when no features in input file or when feature type not exists ?

  • 30 April 2019
  • 8 replies
  • 35 views

Hi,

I published a workspace to the FME Server (2018) of my client that allows to import a specific sheet of an Excel file in Postgres.

But when the input file has zero feature or when the specific sheet doesn't exists, the Workspace doesn't log any error and says that translation was successfull.

Of course, we could open the Excel file to check the data but this workspace is running with automatic processes.

Is there a way to log an error when there are no features in the input file or when the awaited feature type (Excel sheet) not exists ?

Thanks for any help.

icon

Best answer by takashi 30 April 2019, 14:51

View original

8 replies

Userlevel 6
Badge +33

With the FeatureReader transformer you can check for schema features. In Excel the worksheet is a schema. This way you can test if a sheet exists.

testforsheet2019.fmwt

Userlevel 2
Badge +17

The NoFeatureTester from FME Hub might help you.

Userlevel 4
Badge +26

Fantastic transformer! This is an excellent solution for these kinds of problems. What I like to do (if i'm expecting data to be written out) is to stick this python into a shutdown script. It's great for the FME Data Download service which has a habit of creating bad links.

 

 

#This shutdown script is used to catch unhandled excretions. This is the case when the workspace reports a 'Success', however, no features were written out. 

import fme
FeaturesWritten = str(fme.featuresWritten)
#print(FeaturesWritten)
status = fme.status
#print(status)
if status == 1 and FeaturesWritten == "{}":
    print("no data output - unhandled exception")
    raise Exception("unhandled exception")

It wont work if you are writing data with a feature writer, however, if working with normal writers it is a handy script.

 

 

Userlevel 1
Badge +21

I use a pythoncaller to create a feature if no input features exist - then send to a terminator/excel log etc.

I use a pythoncaller to create a feature if no input features exist - then send to a terminator/excel log etc.

Thank you for this tip, I keep it in mind but Takashi's solution is more simple and works exactly as I want. Have a good day !

Thank you once again Takashi, I couldn't expect that a Transformer would do the trick as there is no feature coming out from the reader but I tested and it works perfectly as I want.

With the FeatureReader transformer you can check for schema features. In Excel the worksheet is a schema. This way you can test if a sheet exists.

testforsheet2019.fmwt

Thanks, it's an interesting tip to use the UnmergedRequestor output from a FeatureMerger !

But NoFeatureTester is more simple and do the work perfectly ;)

Have a good day.

Badge +7

I use a pythoncaller to create a feature if no input features exist - then send to a terminator/excel log etc.

Thanks for this suggestion @ebygomm​ ! It too works well for my intention.

Reply